【问题标题】:#1025 - Error on rename (errno: 150) in mysql#1025 - mysql 中重命名错误(错误号:150)
【发布时间】:2013-11-09 05:24:46
【问题描述】:

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

alter table misc drop FOREIGN KEY id

我收到了这个错误

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

【问题讨论】:

标签: mysql


【解决方案1】:

在我的情况下,有必要进行 3 步过程(我的表名为“articulos”,难以删除的索引是“FK_Departamento_ID”)

  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;
    

【讨论】:

    【解决方案2】:
    SHOW CREATE TABLE misc ;
    

    你不能使用列名来删除外键,运行上面的查询来找出正确的名字,比如misc_ibfk_1

    嘿,是这个名字:

    alter table misc drop FOREIGN KEY  misc_ibfk_1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-04
      • 2011-05-01
      • 1970-01-01
      • 2016-02-08
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      相关资源
      最近更新 更多