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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章