我为提出与此主题相关的问题而道歉,我知道这个主题已经在其他一些帖子上进行了讨论,并且它的重复类型,但我所经历的帖子并没有帮助我解决我的问题。
我有以下SQL代码来添加两个表:
CREATE TABLE IF NOT EXISTS `opa`.`iddocumenttype`(
`iddocumenttypeid` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY(`iddocumenttypeid`),
KEY (`iddocumenttypeid`)
) ENGINE=INNODB CHARSET=utf8;
和
CREATE TABLE IF NOT EXISTS `opa`.`identificationdocumentdetails`(
`identificationdocumentdetailsid` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`IDdocumenttypeid` INT(11) UNSIGNED NOT NULL,
`IDdocumentnumber` VARCHAR(128),
`name` VARCHAR(200) COMMENT 'Exact name as on idDoc?',
`dateofissue` DATE CHECK (dateofissue < CURRENT_DATE()),
`placeofissue` VARCHAR(128),
`validtill` DATE CHECK (validtill > CURRENT_DATE()),
PRIMARY KEY (`identificationdocumentdetailsid`),
CONSTRAINT `FK_identificationdocumentdetails_iddocumenttype` FOREIGN KEY (`IDdocumenttypeid`) REFERENCES `opa`.`iddocumenttype`(`iddocumenttypeid`)) ENGINE=INNODB CHARSET=utf8;
现在,当我运行查询以创建第二个表identificationdocumentdetails
时,我收到以下错误:
Error Code: 1005
Can't create table 'opa.identificationdocumentdetails' (errno: 150)
我不明白为什么会发生这种情况,我确信有些事情与CONSTRAINT
行有关,因为当我删除这一行时:
CONSTRAINT `FK_identificationdocumentdetails_iddocumenttype` FOREIGN KEY (`IDdocumenttypeid`) REFERENCES `opa`.`iddocumenttype`(`iddocumenttypeid`)
商店程序运作正常,但我想我不知道这里出了什么问题,有人请指出我在这里看不到的东西......
答案 0 :(得分:2)
`IDdocumenttypeid` INT(11)
identificationdocumentdetails
表中的需要与引用的列完全相同,即
`iddocumenttypeid` INT(11) UNSIGNED NOT NULL