Mysql报错1091解决办法_列在那里,但是当我尝试删除它时,说MYSQL中没有列? **错误代码:1091。无法删除... **...

bd96500e110b49cbb3cd949968f18be7.png

I try to run the following query:

ALTER TABLE ORDER_DETAIL DROP foreign key USER_ID;

It says:

Error Code: 1091. Can't DROP 'USER_ID'; check that column/key exists

When I run:

ALTER TABLE ORDER_DETAIL DROP COLUMN USER_ID

It says:

Error Code: 1553. Cannot drop index 'USER_ID': needed in a foreign key constraint 0.098 sec

But when I run:

desc ORDER_DETAIL;

I get:

Field,Type,Null,Key,Default,Extra

ORDER_ID,int(11),NO,PRI,NULL,

USER_ID,int(11),NO,MUL,NULL,

ORDER_DATE,date,YES,,NULL,

Can anybody explain what is wrong here and how to fix it?

解决方案

Since MySQL creates an index for the foreign keys so directly trying to drop the foreign key does not work. So the answers provided here does not work.

The right sql query that worked for me is this:

ALTER TABLE ORDER_DETAIL DROP FOREIGN KEY ORDER_DETAIL_ibfk_1;

The important thing to notice here is _ibfk_1

And only after that I could drop the column by using:

ALTER TABLE ORDER_DETAIL DROP COLUMN USER_ID;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值