MySQL 删除索引时出错(errno 150)
我在删除外键索引时遇到问题,总是得到相同的错误
ALTER TABLE `comments` DROP INDEX `id_user`
,输出
1025 - Error on rename of './postuj_cz1/#sql-d834_a0c704'
to './postuj_cz1/comments' (errno: 150)
另一个表上的 id_user
是简单的主键索引。
我正在使用 MySQL 版本 5.0.85
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
还有其他原因。例如,我有一个涉及两个单独的外键列的唯一索引。在删除唯一索引之前,我必须删除有问题的外键。 (显然您可以稍后添加外键。)
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 :这可能就像在删除索引之前删除关系一样简单。
INNODB : this could be as simple as removing the Relation before dropping the Index.
根据 此链接,错误与主键字段的定义有关。该错误与外键索引无关。
检查
COMMENTS
表的主键,确保它不具有UNSIGNED
关键字,而COMMENTS.id_user
外键具有 UNSIGNED 关键字。该关键字导致了问题 - 字段类型不一致。要修复此问题,请将
UNSIGNED
关键字添加到COMMENTS
表的主键定义中。或者从外键定义中删除UNSIGNED
关键字...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 theUNSIGNED
keyword while theCOMMENTS.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 theCOMMENTS
table. Or remove theUNSIGNED
keyword from the foreign key definition...该索引用于“用户”表上的外键,因此
首先,尝试以下命令:
查找与外键上的索引相对应的约束名称,
然后尝试以下命令:
警告:如果尝试删除具有外键名称的外键,您将得到一个错误到!
The index is for an foreign key on 'user' table, so
In first, try this command:
Find the name of the constraint corresponding to the index on the foreign key,
and after that, try the command:
WARNING: If you try to drop the foreign key with the foreign key name, you will have an error to!