unable to drop the foreign key(无法删除外键)
问题描述
我想在我的表中删除外键,但出现此错误消息
I would like to drop the foreign key in my table but been into this error message
mysql> alter table customers drop foreign key customerid;
ERROR 1025 (HY000): Error on rename of '.productscustomers' to '.products#sql2-7ec-a3' (errno: 152)
mysql>
推荐答案
为避免在尝试删除外键时出现此错误,请使用约束名称而不是外键的列名.
To avoid getting this error while trying to drop a foreign key, use the constraint name rather than the column name of the foreign key.
当我尝试时
mysql> ALTER TABLE mytable DROP PRIMARY KEY;
我得到了错误
ERROR 1025 (HY000): Error on rename of '.database#sql-454_3' to '.databasemytable' (errno: 150).
我解决了这个问题:
mysql> ALTER TABLE mytable DROP PRIMARY KEY, ADD PRIMARY KEY (column1,column2,column3);
一些对你有帮助的链接.
Some links that will help you.
链接1
链接 2 [查找已发布作者:Alex Blume 于 2008 年 11 月 7 日下午 5:09 &Hector Delgadillo 于 2011 年 1 月 21 日凌晨 4:57 发布]
link 2 [look for Posted by Alex Blume on November 7 2008 5:09pm & Posted by Hector Delgadillo on January 21 2011 4:57am]
这篇关于无法删除外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法删除外键


基础教程推荐
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01