因?yàn)樯婕暗酵怄I辨嗽,所以需要先刪除外鍵約束糟需,再刪除外鍵列屉佳。##
官方解釋文檔:http://docs.oracle.com/cd/E19957-01/mysql-refman-5.5/storage-engines.html
文檔的一個(gè)章節(jié)13.7.8.6. Better Error Handling when Dropping Indexes里面提到是說(shuō)這個(gè)錯(cuò)誤是mysql的一個(gè)BUG谷朝,現(xiàn)在已經(jīng)解決了。ERROR 1553 (HY000): Cannot drop index 'fooIdx': needed in a foreign key constraint
下面是一個(gè)實(shí)例:
create table goodsType(id int(10) unsigned not null auto_increment,name varchar(45) not null,primary key(id));
create table goods(id int(10) unsigned not null auto_increment,typeId int(10)unsigned not null,
name varchar(50) not null,introduce text(16) not null,price float not null,primary key(id),foreign key(typeId) references goodsType(id));
輸入命令:alter table goods drop typeId時(shí)報(bào)錯(cuò)
解決方案:先刪除約束條件武花,再刪除列
約束條件我沒(méi)有取名字圆凰,可以用show create table goods命令查看系統(tǒng)生成的約束名
命令:
alter table goods drop foreign key [完整性約束名];
alter table goods drop typeId;