1

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;

并运行 create 语句但无济于事。

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

这能证明任何意义吗?

4

1 回答 1

2

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

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.
于 2013-02-18T08:14:22.347 回答