#1025 - 在mysql中重命名出错(errno: 150)

8
我试图删除一张表(misc)中的外键(id),而这个外键在另一张表(main)中是主键(id)。数据库名称为(xxx)。
alter table misc drop FOREIGN KEY id

我遇到了这个错误:
#1025 - 将'.\interview#sql-edc_27'重命名为'.\interview\misc'时发生错误(错误号:150)

我遇到了一些问题。这个主题帮助了我:https://dev59.com/iG855IYBdhLWcg3w6Y1q - Andrey Batalov
2个回答

14
SHOW CREATE TABLE misc ;

您不能使用列名删除外键,请运行上面的查询以找到正确的名称,类似于misc_ibfk_1

嘿,就是这个名字:

alter table misc drop FOREIGN KEY  misc_ibfk_1

2
在我的情况下,需要进行一个三步骤的过程(我的表名为“articulos”,难以移除的索引是“FK_Departamento_ID”)。
  1. For knowing the name of table, I executed:

    SHOW INDEX FROM articulos;
    
  2. This statement resolved the issue (#1025, errno: 150), but the index remained in the table

    ALTER TABLE articulos DROP FOREIGN KEY FK_Departamento_ID;
    
  3. The following statement finally wiped out the index

    DROP INDEX FK_Departamento_ID ON articulos;
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接