mysql删除外键提示errno152
mysql> alter table product drop foreign key num;
1025 - Error on rename of '.\student\product' to '.\student\#sql2-e38-e' (errno: 152)
删除外键约束的时候提示errno152,这里并不是不能删除外键,而是使用了错误的名称,但是我的名称并没有错。这时我们可以查看product的详细信息。
mysql> show create table product;
-------------------------------------------------------+
| product | CREATE TABLE `product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(11) DEFAULT NULL,
`price` int(11) DEFAULT NULL,
`num` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `num` (`num`),
CONSTRAINT `product_ibfk_1` FOREIGN KEY (`num`) REFERENCES `category` (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 |
+---------+-------------------------------------------------
这里:**CONSTRAINT product_ibfk_1**
FOREIGN KEY (num
) REFERENCES category
(cid
)
并不是太清楚mysql中为什么会将名字设置成这个,这时 只需要将删除语句修改成
mysql> alter table product drop foreign key product_ibfk_1;
Query OK, 8 rows affected
Records: 8 Duplicates: 0 Warnings: 0
删除约束条件成功!