简体   繁体   English

删除索引时出现MySQL错误(错误150)

[英]MySQL Error when dropping index (errno 150)

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. 另一个表上的id_user是简单的主键索引。

I'm using MySQL version 5.0.85 我使用的是MySQL 5.0.85版本

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.) (显然你可以在之后添加外键。)

INNODB:这可能就像删除Index之前删除Relation一样简单。

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. 检查COMMENTS表的主键,以确保它没有UNSIGNED关键字,而COMMENTS.id_user外键具有UNSIGNED关键字。 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. 要解决此问题,请将UNSIGNED关键字添加到COMMENTS表的主键定义中。 Or remove the UNSIGNED keyword from the foreign key definition... 或者从外键定义中删除UNSIGNED关键字...

The index is for an foreign key on 'user' table, so In first, try this command: 索引是'user'表中的外键,所以首先尝试这个命令:

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! 警告:如果您尝试使用外键名称删除外键,则会出错!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM