MySQL Error when dropping index (errno 150)

最后都变了- 提交于 2019-12-10 03:19:06

问题


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


回答1:


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




回答2:


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




回答3:


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




回答4:


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!



来源:https://stackoverflow.com/questions/1451042/mysql-error-when-dropping-index-errno-150

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!