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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19668682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:16:08  来源:igfitidea点击:

#1025 - Error on rename (errno: 150) in mysql

mysql

提问by black

I am trying to drop a foreign key(id) in one table(misc) which is the primary key(id) in table(main). db name(xxx)

我试图在一个表(misc)中删除一个外键(id),它是表(主)中的主键(id)。数据库名称(xxx)

alter table misc drop FOREIGN KEY id

I am getting this error

我收到此错误

#1025 - Error on rename of '.\interview#sql-edc_27' to '.\interview\misc' (errno: 150)

#1025 - 将 '.\interview#sql-edc_27' 重命名为 '.\interview\misc' 时出错(错误号:150)

回答by Mihai

SHOW CREATE TABLE misc ;

You can't drop the foreign key using the column name,run the above query to find out the correct name,something like misc_ibfk_1

您不能使用列名删除外键,运行上面的查询以找出正确的名称,例如 misc_ibfk_1

Heh,IT IS this name:

呵呵,是这个名字:

alter table misc drop FOREIGN KEY  misc_ibfk_1

回答by ZooMMX

In my case, was necessary to make a 3-step process (my table is named "articulos", and the hard-to-remove index is "FK_Departamento_ID")

就我而言,有必要进行 3 步过程(我的表名为“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;
    
  1. 为了知道表的名称,我执行了:

    SHOW INDEX FROM articulos;
    
  2. 此语句解决了问题(#1025,errno: 150),但索引仍保留在表中

    ALTER TABLE articulos DROP FOREIGN KEY FK_Departamento_ID;
    
  3. 下面的语句终于抹掉了索引

    DROP INDEX FK_Departamento_ID ON articulos;