MySQL Error when dropping index (errno 150)

2019-04-24 08:21发布

I've got problem with dropping foreign key index, I always get the same error

 ALTER TABLE `comments` DROP INDEX `id_user`  

which outputs

 1025 - Error on rename of './postuj_cz1/#sql-d834_a0c704' 
 to './postuj_cz1/comments' (errno: 150) 

The id_user on the other table is simple primary key index.

I'm using MySQL version 5.0.85

4条回答
男人必须洒脱
2楼-- · 2019-04-24 09:00

There are other causes too. For example I had a unique index involving two separate foreign key columns. I had to drop the foreign keys in question before I could drop the unique index. (And obviously you can add the foreign keys back afterward.)

查看更多
beautiful°
3楼-- · 2019-04-24 09:11

INNODB : this could be as simple as removing the Relation before dropping the Index.

查看更多
何必那么认真
4楼-- · 2019-04-24 09:16

The index is for an foreign key on 'user' table, so In first, try this command:

SHOW CREATE TABLE my_table

Find the name of the constraint corresponding to the index on the foreign key,

and after that, try the command:

ALTER TABLE my_table DROP FOREIGN KEY FK_myconstraintcode

WARNING: If you try to drop the foreign key with the foreign key name, you will have an error to!

查看更多
女痞
5楼-- · 2019-04-24 09:23

According to this link, the error relates to the definition of the primary key field. The error isn't about the foreign key index.

Check the primary key for the COMMENTS table to make sure it does not have the UNSIGNED keyword while the COMMENTS.id_user foreign key had the UNSIGNED keyword. This keyword was causing the problem - inconsistent type of field.

To fix, add the UNSIGNED keyword to the primary key definition for the COMMENTS table. Or remove the UNSIGNED keyword from the foreign key definition...

查看更多
登录 后发表回答