删除带有外键的列
在带有 inno_db 引擎的 mysql DB 上,
我有一个带有外键的表。 我想删除该列(当然还有外键和关联的索引 - 我不需要整个列!)
现在,简单地删除它会产生错误: 一般错误:1025 将“.\road_dmy#sql-19d8_2be”重命名为“.\road_dmy\contact”时出错(errno:150)
听起来这是一个已知问题。 http://bugs.mysql.com/bug.php?id=15317
但无论如何,我应该怎么做才能删除此专栏?我非常确定否则可能没有人会使用这个数据库
(顺便说一句,我怎样才能知道上面神秘错误消息的真实细节?)
On my mysql DB with inno_db engine,
I have a table with a foreign key.
I want to drop the column (along with the foreign key and the associated index of course - i don't need the whole column!)
Now, simply dropping it yields an error:
General error: 1025 Error on rename of '.\road_dmy#sql-19d8_2be' to '.\road_dmy\contact' (errno: 150)
It sounds like this is a known issue.
http://bugs.mysql.com/bug.php?id=15317
But anyway, what should i do to drop this column? I'm very sure it's possible nobody would use this DB otherwise
(and b.t.w. how can I know the true details of the mysterious error message above?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须先放下钥匙。我不知道您的表的名称,但我会通过示例向您提供总体策略。假设您有以下 2 个 InnoDB 表:
您可以使用以下命令删除表
B
中的a_id
列:You must drop the key first. I don't know the names of your tables but I'll give you the general strategy by example. Suppose you have the following 2 InnoDB tables:
You can drop the
a_id
column in tableB
using the following command:要查看与表相关的所有外键,请使用以下命令:
该命令将输出包含外键约束的创建表查询,例如:
现在使用以下命令删除外键关系:
现在您的外键关系消失了,您可以安全地删除该列:
请参考:
删除外键约束
To view all the foreign keys related to the table use the following command:
This command will output the create table query which contains the foreign key constraints, for example:
Now use the below command to drop the foreign key relation:
Now that your foreign key relation is gone you can safely delete the column:
Please refer:
Dropping Foreign Key Constraints