MySQL: 无法创建表 (errno: 150)

标签 mysql sql phpmyadmin mysql-error-150

我正在尝试导入 .sql 文件,但创建表失败。

这是失败的查询:

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,删除了所有表,现在我尝试导入它,为什么会失败?

MySQL: Can't create table './dbname/data.frm' (errno: 150)

最佳答案

来自MySQL - FOREIGN KEY Constraints Documentation :

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: 无法创建表 (errno: 150),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33635100/

相关文章:

c# - LINQ to Entities - 更新二进制字段

mysql - 如何在 MySQL Group By 查询中查找唯一值?

mysql - 在 Doctrine2 的选择中使用比较作为别名

php - 关于MySQL安全: charset,转义字符等的困惑

php - 用于查找和替换的 SQL 查询不起作用

PHP : Can't access phpmyadmin on a local network: Forbidden

php - 如何使多个列在同一个表中唯一

mysql - 我不知道如何在 sequelize 中根据类别对费用求和

mysql - 触发器替代方案中的动态 SQL

java - 通过结果集检索单个值并将其与字符串值进行比较