1. <legend id='nTS4C'><style id='nTS4C'><dir id='nTS4C'><q id='nTS4C'></q></dir></style></legend>

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

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

      <bdo id='nTS4C'></bdo><ul id='nTS4C'></ul>

      <tfoot id='nTS4C'></tfoot>

    1. MySQL 错误 1215:无法添加外键约束

      时间:2023-08-18

      <legend id='aGtg9'><style id='aGtg9'><dir id='aGtg9'><q id='aGtg9'></q></dir></style></legend>

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

          <tbody id='aGtg9'></tbody>
        <tfoot id='aGtg9'></tfoot>

              <bdo id='aGtg9'></bdo><ul id='aGtg9'></ul>

              1. <i id='aGtg9'><tr id='aGtg9'><dt id='aGtg9'><q id='aGtg9'><span id='aGtg9'><b id='aGtg9'><form id='aGtg9'><ins id='aGtg9'></ins><ul id='aGtg9'></ul><sub id='aGtg9'></sub></form><legend id='aGtg9'></legend><bdo id='aGtg9'><pre id='aGtg9'><center id='aGtg9'></center></pre></bdo></b><th id='aGtg9'></th></span></q></dt></tr></i><div id='aGtg9'><tfoot id='aGtg9'></tfoot><dl id='aGtg9'><fieldset id='aGtg9'></fieldset></dl></div>
              2. 本文介绍了MySQL 错误 1215:无法添加外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试将我的新架构转发到我的数据库服务器上,但我不知道为什么我会收到这个错误.

                I am trying to forward engineer my new schema onto my database server, but I can't figure out why I am getting this error.

                我试图在这里搜索答案,但我发现的所有内容都说要么将数据库引擎设置为 InnoDB,要么确保我尝试用作外键的键是主键他们自己的桌子.如果我没记错的话,这两件事我都做过.我还能做什么?

                I've tried to search for the answer here, but everything I've found has said to either set the database engine to InnoDB or to make sure the keys I'm trying to use as a foreign key are primary keys in their own tables. I have done both of these things, if I'm not mistaken. What else can I do?

                Executing SQL script in server
                
                ERROR: Error 1215: Cannot add foreign key constraint
                
                -- -----------------------------------------------------
                -- Table `Alternative_Pathways`.`Clients_has_Staff`
                -- -----------------------------------------------------
                

                CREATE  TABLE IF NOT EXISTS `Alternative_Pathways`.`Clients_has_Staff` (
                  `Clients_Case_Number` INT NOT NULL ,
                  `Staff_Emp_ID` INT NOT NULL ,
                  PRIMARY KEY (`Clients_Case_Number`, `Staff_Emp_ID`) ,
                  INDEX `fk_Clients_has_Staff_Staff1_idx` (`Staff_Emp_ID` ASC) ,
                  INDEX `fk_Clients_has_Staff_Clients_idx` (`Clients_Case_Number` ASC) ,
                  CONSTRAINT `fk_Clients_has_Staff_Clients`
                    FOREIGN KEY (`Clients_Case_Number` )
                    REFERENCES `Alternative_Pathways`.`Clients` (`Case_Number` )
                    ON DELETE NO ACTION
                    ON UPDATE NO ACTION,
                  CONSTRAINT `fk_Clients_has_Staff_Staff1`
                    FOREIGN KEY (`Staff_Emp_ID` )
                    REFERENCES `Alternative_Pathways`.`Staff` (`Emp_ID` )
                    ON DELETE NO ACTION
                    ON UPDATE NO ACTION)
                ENGINE = InnoDB
                

                SQL 脚本执行完成:语句:7 条成功,1 条失败

                SQL script execution finished: statements: 7 succeeded, 1 failed

                这是父表的 SQL.

                CREATE  TABLE IF NOT EXISTS `Alternative_Pathways`.`Clients` (
                  `Case_Number` INT NOT NULL ,
                  `First_Name` CHAR(10) NULL ,
                  `Middle_Name` CHAR(10) NULL ,
                  `Last_Name` CHAR(10) NULL ,
                  `Address` CHAR(50) NULL ,
                  `Phone_Number` INT(10) NULL ,
                  PRIMARY KEY (`Case_Number`) )
                ENGINE = InnoDB
                
                CREATE  TABLE IF NOT EXISTS `Alternative_Pathways`.`Staff` (
                  `Emp_ID` INT NOT NULL ,
                  `First_Name` CHAR(10) NULL ,
                  `Middle_Name` CHAR(10) NULL ,
                  `Last_Name` CHAR(10) NULL ,
                  PRIMARY KEY (`Emp_ID`) )
                ENGINE = InnoDB
                

                推荐答案

                我猜 Clients.Case_Number 和/或 Staff.Emp_ID 并不完全相同数据类型为 Clients_has_Staff.Clients_Case_NumberClients_has_Staff.Staff_Emp_ID.

                I'm guessing that Clients.Case_Number and/or Staff.Emp_ID are not exactly the same data type as Clients_has_Staff.Clients_Case_Number and Clients_has_Staff.Staff_Emp_ID.

                也许父表中的列是INT UNSIGNED?

                它们在两个表中的数据类型必须完全相同.

                They need to be exactly the same data type in both tables.

                这篇关于MySQL 错误 1215:无法添加外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 MySQL 中更新(如果存在),如果不存在则插 下一篇:如何删除 MySQL 表上的重复项?

                相关文章

                最新文章

                1. <i id='mT7Ts'><tr id='mT7Ts'><dt id='mT7Ts'><q id='mT7Ts'><span id='mT7Ts'><b id='mT7Ts'><form id='mT7Ts'><ins id='mT7Ts'></ins><ul id='mT7Ts'></ul><sub id='mT7Ts'></sub></form><legend id='mT7Ts'></legend><bdo id='mT7Ts'><pre id='mT7Ts'><center id='mT7Ts'></center></pre></bdo></b><th id='mT7Ts'></th></span></q></dt></tr></i><div id='mT7Ts'><tfoot id='mT7Ts'></tfoot><dl id='mT7Ts'><fieldset id='mT7Ts'></fieldset></dl></div>
                2. <legend id='mT7Ts'><style id='mT7Ts'><dir id='mT7Ts'><q id='mT7Ts'></q></dir></style></legend>

                    <bdo id='mT7Ts'></bdo><ul id='mT7Ts'></ul>

                  1. <tfoot id='mT7Ts'></tfoot>

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