MySQL:无法建立表格(错误编号:150)

时间:2019-05-09 09:54:01

标签: mysql constraints

我正在尝试创建一个表,该表具有引用另一张表的几列,其父表如下:

create table asofdatepshipinvestments ( 
    AsOfDate DATETIME not null,
    PShipEnt_Id INTEGER not null,
    CompEnt_ID INTEGER not null,
    CompStage VARCHAR(32),
    CurrShares DECIMAL(19,0),
    CurrOwn DECIMAL(10,4),
    CurrValuation DECIMAL(19,4),
    CurrMktValue DECIMAL(19,4),
    CurrCost DECIMAL(19,4),
    CurrValue DECIMAL(19,4),
    UserCost DECIMAL(19,4) not null,
    RealizedCost DECIMAL(19,4),
    RealizedValue DECIMAL(19,4),
    TotalCost DECIMAL(19,4),
    TotalValue DECIMAL(19,4),
    psource VARCHAR(64),
    pnote VARCHAR(2048), constraint asofdatepshipinvestments_pk primary key (PShipEnt_Id, AsOfDate, CompEnt_ID)) ENGINE = InnoDB;

这是我要创建的表:

CREATE TABLE asofdatepshipinvrealznsources (
  AsOfDate DATETIME NOT NULL,
  PShipEnt_Id INTEGER NOT NULL,
  CompEnt_ID INTEGER NOT NULL,
  SourceEnt_ID INTEGER NOT NULL,
  realizedcostfx DECIMAL(19,4) DEFAULT '0.0000',
  realizedvaluefx DECIMAL(19,4) DEFAULT '0.0000',
  PRIMARY KEY (AsOfDate, PShipEnt_Id, CompEnt_ID, SourceEnt_ID),
  CONSTRAINT asofdates_asofdatepshipinvrealznsources_FK1 FOREIGN KEY (AsOfDate) REFERENCES asofdates (AsOfDate),
  CONSTRAINT asofdatepshipinvestments_asofdatepshipinvrealznsources_FK1 FOREIGN KEY (AsOfDate, PShipEnt_Id, CompEnt_ID) REFERENCES asofdatepshipinvestments (AsOfDate, PShipEnt_Id, CompEnt_ID),
  CONSTRAINT asofdatepshipinvestments_asofdatepshipinvrealznsources_FK2 FOREIGN KEY (AsOfDate, PShipEnt_Id, SourceEnt_ID) REFERENCES asofdatepshipinvestments (AsOfDate, PShipEnt_Id, CompEnt_ID)
) ENGINE=INNODB;

即使数据类型和排序相似且约束名称是唯一的,我仍然会遇到此错误:Can't create table safpstar.asofdatepshipinvrealznsources' (errno: 150) 无法弄清楚还有什么可能是问题。 预先感谢。

0 个答案:

没有答案