MySQL 无法创建表 (errno : 150) - table has no foreign key

标签 mysql runtime-error

1- 我知道这个问题已经被问过好几次了。 2-我都读过 3- 它没有解决我的问题 4- 我知道它与外键关系有关

我只是想创建一个没有外键的表,但我仍然得到这个错误

Can't create table 'pwp.decision_nodes' (errno: 150)

这是建表语句

CREATE TABLE IF NOT EXISTS `decision_nodes` (
  `id` BIGINT(45) NOT NULL AUTO_INCREMENT,
  `decision_node_id` BIGINT(50) NOT NULL,
  KEY pk_index(`id`),
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=125 DEFAULT CHARSET=utf8;

我试过了

SET FOREIGN_KEY_CHECKS = 0;

并运行创建语句但无济于事。

MySQL版本

'5.5.21-log'

我不太确定,但我认为以前(很久以前)在数据库中有一个同名的表,它可能被重命名或删除了。这能算是暗示吗?

该历史表(重命名或删除)与另外两个表 help_entityref_cancer_type 有外键关系

CREATE TABLE `help_entity` (
  `id` bigint(50) NOT NULL AUTO_INCREMENT,
  `type` int(50) NOT NULL,
  `comments` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=171 DEFAULT CHARSET=utf8


CREATE TABLE `ref_cancer_type` (
  `id` char(3) NOT NULL,
  `description` varchar(100) DEFAULT NULL,
  `is_active` tinyint(4) NOT NULL,
  `display_order` decimal(10,0) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

这有什么意义吗?

最佳答案

我认为您的其他一些表具有对您现在要创建的表的外键引用。

参见 http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

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 right column names and types, and it must have 
indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error 
number 1005 and refers to error 150 in the error message.

关于MySQL 无法创建表 (errno : 150) - table has no foreign key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14931620/

相关文章:

C++ 树指针错误

vba 运行时错误 13 - 尝试执行循环时

php - 如何从 URL 中隐藏用户 ID 和密码?

mysql - 对不同列中的 mysql 数据进行排序

文件上的mysql加密 key 存储

regex - 在正则表达式中,神秘错误 : assertion 'tree->num_tags == num_tags' failed in executing regexp: file 'tre-compile.c' , 第 634 行

java - 尝试用 Java 运行我编译的程序时出错

php - 当 mysql 中存在 unicode 字符时,无法将条目存储为字符串

c# - 当我尝试在 asp.net mvc 中添加新用户时插入冲突

java - Android-将网页内容获取到字符串中