MySQL:MySQL不能刪除外鍵,抱錯Error on rename of ./ruler/test2child to ./ruler/#sql2-298-92 (errno: 152)
曾經這是MySQL的一個bug,但是現在只是MySQL的一個不友好的地方。
例子如下:
1
2
3
|
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報的錯實在離譜。
正確的錯誤信息要如下查詢才能知道:
1
2
3
4
5
6
7
8
9
|
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" . |
另外外鍵的其他操作也有類似情況:
比如外鍵 新建報錯:
1
2
3
4
5
6
7
8
9
|
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
刪除外鍵的做法:
//先刪除外鍵名,再刪外鍵字段(mysql官方提供)
例:
1
2
|
alter table task drop foreign key FK_Reference_7; alter table task drop column `assigned`; |
以上所述是小編給大家介紹的MySQL刪除外鍵問題小結,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://blog.csdn.net/wangle100wangle/article/details/3301271