无法创建外键InnoDB

时间:2014-02-25 13:05:52

标签: mysql database innodb mysql-workbench

我敢打赌,这很容易。但我很挣扎。我使用MySQL Workbench创建了一个DB模型,当我生成一个脚本并尝试针对我的本地MySQL运行它时,它失败并出现以下错误:(使用SHOW ENGINE INNODB STATUS\G时)

Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.

我确实知道FK任务有问题,但是什么?根据{{​​3}}帖子,您应该在两个参考表上都有一个可用的INDEX。我在两个'创建语句'中添加了INDEX'es但它仍然失败并出现相同的错误。任何帮助将不胜感激。

-- -----------------------------------------------------
-- Table `Flyplass`.`Rullebane`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Flyplass`.`Rullebane` (
  `Rkode` INT NOT NULL,
  `Pos` INT NOT NULL,
  `Lengde` INT NOT NULL,
  `FKode` INT NOT NULL,
  PRIMARY KEY (`Rkode`),
  INDEX `FK_Fkode` (`FKode` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Flyplass`.`FlyplassInfo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Flyplass`.`FlyplassInfo` (
  `FKode` INT NOT NULL,
  `Fnavn` VARCHAR(45) NULL,
  `Ftelefon` VARCHAR(45) NULL,
  PRIMARY KEY (`FKode`),
  CONSTRAINT `FK_FlyplassID`
    FOREIGN KEY (`FKode`)
    REFERENCES `Flyplass`.`Rullebane` (`FKode`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

0 个答案:

没有答案