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,則表創建失敗,因為外鍵約束沒有正確形成。
添加回答
舉報