错误代码:1005 - 无法创建 table(错误编号:150)
Error Code: 1005 - Can't create table (errno: 150)
我为提出与此主题相关的问题而道歉,我知道这个主题已在其他几个帖子中讨论过,并且它有点重复,但我浏览过的帖子并没有帮助我解决我的问题。
我有以下 SQL 代码来添加两个 tables:
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;
现在,当我 运行 创建第二个 table 即 identificationdocumentdetails
的查询时,出现以下错误:
Error Code: 1005
Can't create table 'opa.identificationdocumentdetails' (errno: 150)
我不明白为什么会这样,我确定某些事情与 CONSTRAINT
行有关,因为当我删除此行时:
CONSTRAINT `FK_identificationdocumentdetails_iddocumenttype` FOREIGN KEY (`IDdocumenttypeid`) REFERENCES `opa`.`iddocumenttype`(`iddocumenttypeid`)
存储程序工作正常,但我想我不知道这里出了什么问题,有人可以向我指出我在这里没有看到什么....
`IDdocumenttypeid` INT(11)
in identificationdocumentdetails
table 需要与引用的列的类型完全相同,即
`iddocumenttypeid` INT(11) UNSIGNED NOT NULL
我为提出与此主题相关的问题而道歉,我知道这个主题已在其他几个帖子中讨论过,并且它有点重复,但我浏览过的帖子并没有帮助我解决我的问题。
我有以下 SQL 代码来添加两个 tables:
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;
现在,当我 运行 创建第二个 table 即 identificationdocumentdetails
的查询时,出现以下错误:
Error Code: 1005
Can't create table 'opa.identificationdocumentdetails' (errno: 150)
我不明白为什么会这样,我确定某些事情与 CONSTRAINT
行有关,因为当我删除此行时:
CONSTRAINT `FK_identificationdocumentdetails_iddocumenttype` FOREIGN KEY (`IDdocumenttypeid`) REFERENCES `opa`.`iddocumenttype`(`iddocumenttypeid`)
存储程序工作正常,但我想我不知道这里出了什么问题,有人可以向我指出我在这里没有看到什么....
`IDdocumenttypeid` INT(11)
in identificationdocumentdetails
table 需要与引用的列的类型完全相同,即
`iddocumenttypeid` INT(11) UNSIGNED NOT NULL