MySQL:ERROR 1215:无法添加外键约束

时间:2016-04-20 10:46:03

标签: mysql foreign-keys ddl

在尝试在MySQLWorkbench中转发ERD时,我遇到了这个错误:

在服务器中执行SQL脚本 错误:错误1215:无法添加外键约束 SQL代码:

        -- -----------------------------------------------------
        -- Table `mydb`.`Order`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mydb`.`Order` (
          `idOrder` INT NOT NULL AUTO_INCREMENT,
          `Klantnummer` INT NOT NULL,
          `Bezorger1` INT NOT NULL,
          `idTreinbezorger` INT NULL,
          `Bezorger2` INT NULL,
          `Kluiscode` INT NULL,
          `Starttijd` DATETIME NOT NULL,
          `Eindtijd` DATETIME NULL,
          `OphaalAdres` INT NOT NULL,
          `AfleverAdres` INT NOT NULL,
          `idOrderStatus` INT NOT NULL,
          `VerwachteEindtijd` DATETIME NOT NULL,
          PRIMARY KEY (`idOrder`),
          INDEX `fk_Order_OrderStatus1_idx` (`idOrderStatus` ASC),
          INDEX `fk_Order_Treinbezorger1_idx` (`idTreinbezorger` ASC),
          INDEX `fk_Order_Adres1_idx` (`OphaalAdres` ASC),
          INDEX `fk_Order_Adres2_idx` (`AfleverAdres` ASC),
          INDEX `fk_Order_Bezorger1_idx` (`Bezorger2` ASC),
          CONSTRAINT `fk_Order_OrderStatus1`
            FOREIGN KEY (`idOrderStatus`)
            REFERENCES `mydb`.`OrderStatus` (`idOrderStatus`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `fk_Order_Treinbezorger1`
            FOREIGN KEY (`idTreinbezorger`)
            REFERENCES `mydb`.`Treinbezorger` (`idTreinbezorger`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `fk_Order_Adres1`
            FOREIGN KEY (`OphaalAdres`)
            REFERENCES `mydb`.`Adres` (`idAdres`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `fk_Order_Adres2`
            FOREIGN KEY (`AfleverAdres`)
            REFERENCES `mydb`.`Adres` (`idAdres`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `fk_Order_Bezorger1`
            FOREIGN KEY (`Bezorger2`)
            REFERENCES `mydb`.`Bezorger` (`idBezorger`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `fk_Order_Account1`
            FOREIGN KEY (`idOrder`)
            REFERENCES `mydb`.`Account` (`idOrder`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

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

Fetching back view definitions in final form.
Nothing to fetch

我已经读过,我必须使我链接的所有列都需要是相同的数据类型。我检查了所有它们都匹配(都是INT)。

问题是,我做错了什么,我该怎么做才能解决它?

0 个答案:

没有答案