<bdo id='5eKkk'></bdo><ul id='5eKkk'></ul>

<small id='5eKkk'></small><noframes id='5eKkk'>

        <i id='5eKkk'><tr id='5eKkk'><dt id='5eKkk'><q id='5eKkk'><span id='5eKkk'><b id='5eKkk'><form id='5eKkk'><ins id='5eKkk'></ins><ul id='5eKkk'></ul><sub id='5eKkk'></sub></form><legend id='5eKkk'></legend><bdo id='5eKkk'><pre id='5eKkk'><center id='5eKkk'></center></pre></bdo></b><th id='5eKkk'></th></span></q></dt></tr></i><div id='5eKkk'><tfoot id='5eKkk'></tfoot><dl id='5eKkk'><fieldset id='5eKkk'></fieldset></dl></div>

        <legend id='5eKkk'><style id='5eKkk'><dir id='5eKkk'><q id='5eKkk'></q></dir></style></legend>
      1. <tfoot id='5eKkk'></tfoot>

        MySQL 无法删除外键约束中所需的索引

        MySQL Cannot drop index needed in a foreign key constraint(MySQL 无法删除外键约束中所需的索引)
        <legend id='IBKF4'><style id='IBKF4'><dir id='IBKF4'><q id='IBKF4'></q></dir></style></legend>
        1. <small id='IBKF4'></small><noframes id='IBKF4'>

          <i id='IBKF4'><tr id='IBKF4'><dt id='IBKF4'><q id='IBKF4'><span id='IBKF4'><b id='IBKF4'><form id='IBKF4'><ins id='IBKF4'></ins><ul id='IBKF4'></ul><sub id='IBKF4'></sub></form><legend id='IBKF4'></legend><bdo id='IBKF4'><pre id='IBKF4'><center id='IBKF4'></center></pre></bdo></b><th id='IBKF4'></th></span></q></dt></tr></i><div id='IBKF4'><tfoot id='IBKF4'></tfoot><dl id='IBKF4'><fieldset id='IBKF4'></fieldset></dl></div>

                  <bdo id='IBKF4'></bdo><ul id='IBKF4'></ul>
                    <tbody id='IBKF4'></tbody>

                  <tfoot id='IBKF4'></tfoot>
                  本文介绍了MySQL 无法删除外键约束中所需的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要更改我现有的数据库以添加一列.因此,我还想更新 UNIQUE 字段以包含该新列.我正在尝试删除当前索引,但不断收到错误 MySQL 无法删除外键约束中所需的索引

                  I need to ALTER my existing database to add a column. Consequently I also want to update the UNIQUE field to encompass that new column. I'm trying to remove the current index but keep getting the error MySQL Cannot drop index needed in a foreign key constraint

                  CREATE TABLE mytable_a (
                  ID          TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                  Name        VARCHAR(255) NOT NULL,
                  UNIQUE(Name)
                  ) ENGINE=InnoDB;
                  
                  CREATE TABLE mytable_b (
                  ID          TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                  Name        VARCHAR(255) NOT NULL,
                  UNIQUE(Name)
                  ) ENGINE=InnoDB;
                  
                  CREATE TABLE mytable_c (
                  ID          TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                  Name        VARCHAR(255) NOT NULL,
                  UNIQUE(Name)
                  ) ENGINE=InnoDB;
                  
                  
                  CREATE TABLE `mytable` (
                    `ID` int(11) NOT NULL AUTO_INCREMENT,
                    `AID` tinyint(5) NOT NULL,
                    `BID` tinyint(5) NOT NULL,
                    `CID` tinyint(5) NOT NULL,
                    PRIMARY KEY (`ID`),
                    UNIQUE KEY `AID` (`AID`,`BID`,`CID`),
                    KEY `BID` (`BID`),
                    KEY `CID` (`CID`),
                    CONSTRAINT `mytable_ibfk_1` FOREIGN KEY (`AID`) REFERENCES `mytable_a` (`ID`) ON DELETE CASCADE,
                    CONSTRAINT `mytable_ibfk_2` FOREIGN KEY (`BID`) REFERENCES `mytable_b` (`ID`) ON DELETE CASCADE,
                    CONSTRAINT `mytable_ibfk_3` FOREIGN KEY (`CID`) REFERENCES `mytable_c` (`ID`) ON DELETE CASCADE
                  ) ENGINE=InnoDB;
                  
                  
                  
                  
                  mysql> ALTER TABLE mytable DROP INDEX AID;
                  ERROR 1553 (HY000): Cannot drop index 'AID': needed in a foreign key constraint
                  

                  推荐答案

                  您必须删除外键.MySQL 中的外键自动在表上创建索引(有一个 SO Question 主题).

                  You have to drop the foreign key. Foreign keys in MySQL automatically create an index on the table (There was a SO Question on the topic).

                  ALTER TABLE mytable DROP FOREIGN KEY mytable_ibfk_1 ; 
                  

                  这篇关于MySQL 无法删除外键约束中所需的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
                      <tbody id='Lt3mY'></tbody>

                        <i id='Lt3mY'><tr id='Lt3mY'><dt id='Lt3mY'><q id='Lt3mY'><span id='Lt3mY'><b id='Lt3mY'><form id='Lt3mY'><ins id='Lt3mY'></ins><ul id='Lt3mY'></ul><sub id='Lt3mY'></sub></form><legend id='Lt3mY'></legend><bdo id='Lt3mY'><pre id='Lt3mY'><center id='Lt3mY'></center></pre></bdo></b><th id='Lt3mY'></th></span></q></dt></tr></i><div id='Lt3mY'><tfoot id='Lt3mY'></tfoot><dl id='Lt3mY'><fieldset id='Lt3mY'></fieldset></dl></div>

                        <small id='Lt3mY'></small><noframes id='Lt3mY'>

                        <legend id='Lt3mY'><style id='Lt3mY'><dir id='Lt3mY'><q id='Lt3mY'></q></dir></style></legend>
                          <bdo id='Lt3mY'></bdo><ul id='Lt3mY'></ul>
                        • <tfoot id='Lt3mY'></tfoot>