MySQL Error when dropping index (errno 150)

12.1k Views Asked by At

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

There are 4 best solutions below

0
On BEST ANSWER

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

1
On

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

2
On

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

1
On

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!