错误代码:
1091 Can't DROP 'category_id'; check that column/key exists ERROR 1553 (HY000): Cannot drop index 'category_id': needed in a foreign key constraint ERROR 1828 (HY000): Cannot drop column 'category_id': needed in a foreign key constraint user_ibfk_1
在我删除外键列表后,我查看了一下表,外键仍在!
于是我再删一遍
alter table user
DROP FOREIGN KEY category_id;
报错认为该主键已不存在!
我们用show index from user来看看
外键category_id竟然还存在
我们show create table user来看一看
发现外键被CONSTRAINT user_ibfk_1 给约束住了
也就是说MYSQL给外键上了锁,不让你随便删去
我们删除这个约束再删除外键
OK 成功!😘