我收到错误
ERROR 1215(HY000)第11行:无法添加外键约束
两栏都相同,即
suplayer
tinyint(1)unsigned NOT NULL,------------------------
LATEST FOREIGN KEY ERROR
------------------------
2017-04-11 21:57:46 0x700003ab1000 Error in foreign key constraint of table clasdbclone/layer:
FOREIGN KEY (`suplayer`) REFERENCES hvcrateslot(`suplayer`) ON DELETE RESTRICT,
PRIMARY KEY (`layer`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
tinyint(1)unsigned NOT NULL,最新的外键错误状态
DROP TABLE IF EXISTS `hvcrateslot`;
CREATE TABLE `hvcrateslot` (
`hvcrate` tinyint(1) unsigned NOT NULL,
`hvslot` tinyint(1) unsigned NOT NULL,
`hvsubslot` tinyint(1) unsigned NOT NULL,
`suplayer` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`hvcrate`,`hvslot`,`hvsubslot`,`suplayer`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `layer`;
CREATE TABLE `layer` (
`layer` tinyint(1) unsigned NOT NULL,
`suplayer` tinyint(1) unsigned NOT NULL,
INDEX (`suplayer`),
CONSTRAINT `superlayer` FOREIGN KEY (`suplayer`)
REFERENCES hvcrateslot(`suplayer`)
ON DELETE RESTRICT
PRIMARY KEY (`layer`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
如果我限制hvcrateslot表中的主键数量,我的天真惊讶一切正常。
这是我的最低工作DDL
start