4 回答
TA贡献1851条经验 获得超4个赞
SHOW ENGINE INNODB STATUS;
LATEST FOREIGN KEY ERROR
CREATE TABLE t1(id INTEGER);CREATE TABLE t2(t1_id INTEGER, CONSTRAINT FOREIGN KEY (t1_id) REFERENCES t1 (id));
Can't create table 'test.t2' (errno: 150)
SHOW ENGINE INNODB STATUS;
------------------------ LATEST FOREIGN KEY ERROR ------------------------ 130811 23:36:38 Error in foreign key constraint of table test/t2: FOREIGN KEY (t1_id) REFERENCES t1 (id)): 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.
SHOW INDEX FROM t1
t1
t1
TA贡献1824条经验 获得超6个赞
ALTER TABLE `dbname`.`tablename` CHANGE `fieldname` `fieldname` int(10) UNSIGNED NULL;
TA贡献1860条经验 获得超8个赞
如果您重新创建一个被删除的表,它必须有一个符合引用它的外键约束的定义。如前面所述,它必须具有正确的列名和类型,并且必须在引用的键上有索引。如果不满足这些要求,MySQL将返回错误号1005,并在错误消息中引用错误150。如果MySQL从CREATETABLE语句中报告错误号1005,并且错误消息引用错误150,则表创建失败,因为外键约束没有正确形成。
添加回答
举报