欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL刪除外鍵問題小結(jié)

 更新時(shí)間:2016年08月18日 10:10:59   作者:wangle100wangle  
mysql刪除外鍵抱錯(cuò)Error on rename of ./ruler/test2child to ./ruler/#sql2-298-92 (errno: 152),怎么回事,有好的方法可以解決嗎?下面看下腳本之家小編給大家?guī)?lái)的解決思路

MySQL:MySQL不能刪除外鍵,抱錯(cuò)Error on rename of ./ruler/test2child to ./ruler/#sql2-298-92 (errno: 152)

曾經(jīng)這是MySQL的一個(gè)bug,但是現(xiàn)在只是MySQL的一個(gè)不友好的地方。

例子如下:

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

這里并不是不能刪除外鍵,而是使用了錯(cuò)誤的外鍵名稱,但是MySQL報(bào)的錯(cuò)實(shí)在離譜。
正確的錯(cuò)誤信息要如下查詢才能知道:

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".

另外外鍵的其他操作也有類似情況:

比如外鍵 新建報(bào)錯(cuò):

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.

測(cè)試數(shù)據(jù)庫(kù)版本為:

5.2.0-falcon-alpha-community-nt

刪除外鍵的做法:

//先刪除外鍵名,再刪外鍵字段(mysql官方提供)

例:

alter table task drop foreign key FK_Reference_7;
alter table task drop column `assigned`;

以上所述是小編給大家介紹的MySQL刪除外鍵問題小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論