MySQL不能删除外键,抱错Error on rename of './ruler/test2child' to './ruler/#sql2-298-92' (errno: 152)

曾经这是MySQL的一个bug,但是现在只是MySQL的一个不友好的地方。
例子如下:

mysql> ALTER TABLE ruler.test2child DROP FOREIGN KEY test;
ERROR 1025 : Error on rename of './ruler/test2child' to './ruler/#sql2-298-8f' (errno:
152)

    这里并不是不能删除外键,而是使用了错误的外键名称,但是MySQL报的错实在离谱。
正确的错误信息要如下查询才能知道:
mysql> show innodb status;
------------------------
LATEST FOREIGN KEY ERROR
------------------------
071222 20:48:26 Error in dropping of a foreign key constraint of table
"ruler"."test2child",
in SQL command
ALTER TABLE ruler.test2child DROP FOREIGN KEY test
Cannot find a constraint with the given id "test".

    另外外键的其他操作也有类似情况:
比如外键 新建报错:
Can't create table 'ruler.#sql-298_92' (errno: 150)

show innodb status;
------------------------
LATEST FOREIGN KEY ERROR
------------------------
071222 20:18:57 Error in foreign key constraint of table ruler/#sql-298_8d:
 FOREIGN KEY (test2code) REFERENCES ruler.test2 (test) on delete set null:
You have defined a SET NULL condition though some of the
columns are defined as NOT NULL.


测试数据库版本为:

5.2.0-falcon-alpha-community-nt

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值