問題描述
我正在嘗試導入 .sql 文件,但在創建表時失敗.
I am trying to import a .sql file and its failing on creating tables.
這是失敗的查詢:
CREATE TABLE `data` (
`id` int(10) unsigned NOT NULL,
`name` varchar(100) NOT NULL,
`value` varchar(15) NOT NULL,
UNIQUE KEY `id` (`id`,`name`),
CONSTRAINT `data_ibfk_1` FOREIGN KEY (`id`) REFERENCES `keywords` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
我從同一個數據庫導出了 .sql,我刪除了所有表,現在我試圖導入它,為什么它失敗了?
I exported the .sql from the same database, I dropped all the tables and now im trying to import it, why is it failing?
MySQL: 無法創建表 './dbname/data.frm' (errno: 150)
MySQL: Can't create table './dbname/data.frm' (errno: 150)
推薦答案
來自 MySQL - 外鍵約束文檔:
如果你重新創建一個被刪除的表,它必須有一個符合引用它的外鍵約束的定義.如前所述,它必須具有正確的列名和類型,并且必須在引用的鍵上具有索引.如果這些都不滿足,MySQL 會返回 Error 1005 并在錯誤消息中引用 Error 150,這意味著沒有正確形成外鍵約束. 同樣,如果由于錯誤 150,ALTER TABLE 失敗,這意味著對于更改后的表,外鍵定義的格式不正確.
If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the correct column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns Error 1005 and refers to Error 150 in the error message, which means that a foreign key constraint was not correctly formed. Similarly, if an ALTER TABLE fails due to Error 150, this means that a foreign key definition would be incorrectly formed for the altered table.
這篇關于MySQL:無法創建表(錯誤號:150)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!