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_entity
和 ref_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/