如何解决MySQL上的前向工程师问题?

时间:2018-12-31 13:18:20

标签: mysql foreign-keys mysql-workbench erd forward-engineer

我正在尝试前向工程师我创建的ERD,但是前向工程师流程将输出错误给了我。 ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'straatid' for constraint 'verzinzelf3' in the referenced table 'locatie'

但这很奇怪,因为列名 straatid 实际上位于表 Locatie 中。表 Team Locatie 之间的关系与 Locatie Plant ,但是在表 Locatie 的关系之间似乎只有一个错误 Plant 。我真的不知道如何解决此错误。有人可以帮我解决这个问题吗?。

这是对应该执行的 SQL脚本的审查:

-- MySQL Workbench Forward Engineering

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;

USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`table1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`table1` (
  `StraatID` VARCHAR(45) NOT NULL,
  `Straat` VARCHAR(45) NULL,
  `Latitude` VARCHAR(45) NULL,
  `Longitude` VARCHAR(45) NULL,
  PRIMARY KEY (`StraatID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Locatie`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Locatie` (
  `Huisnr` VARCHAR(45) NOT NULL,
  `StraatID` VARCHAR(45) NOT NULL,
  `Toevoeging` VARCHAR(45) NULL,
  PRIMARY KEY (`Huisnr`, `StraatID`),
  UNIQUE INDEX `StraatID_UNIQUE` (`StraatID` ASC) VISIBLE,
  UNIQUE INDEX `Huisnr_UNIQUE` (`Huisnr` ASC) VISIBLE,
  INDEX `verzinzelf2_idx` (`StraatID` ASC) VISIBLE,
  CONSTRAINT `verzinzelf2`
    FOREIGN KEY (`StraatID`)
    REFERENCES `mydb`.`table1` (`StraatID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Team`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Team` (
  `Teamnr` INT NOT NULL,
  `StraatID` VARCHAR(45) NOT NULL,
  `Huisnr` VARCHAR(45) NOT NULL,
  `StraatID1` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`Teamnr`),
  INDEX `verzinzelf5_idx` (`Huisnr` ASC, `StraatID1` ASC) VISIBLE,
  CONSTRAINT `verzinzelf5`
    FOREIGN KEY (`Huisnr` , `StraatID1`)
    REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Eigenaar`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Eigenaar` (
  `Eigenaar` INT NOT NULL,
  PRIMARY KEY (`Eigenaar`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Plant`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Plant` (
  `Plant beschrijving` VARCHAR(45) NOT NULL,
  `Kaartlokatie` VARCHAR(45) NOT NULL,
  `Oppervlakte` VARCHAR(45) NOT NULL,
  `Eigenaar` INT NOT NULL,
  `Huisnr` VARCHAR(45) NOT NULL,
  `StraatID` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`Plant beschrijving`, `Kaartlokatie`, `Oppervlakte`),
  INDEX `verzinzelf4_idx` (`Eigenaar` ASC) VISIBLE,
  INDEX `verzinzelf3_idx` (`Huisnr` ASC, `StraatID` ASC) VISIBLE,
  CONSTRAINT `verzinzelf4`
    FOREIGN KEY (`Eigenaar`)
    REFERENCES `mydb`.`Eigenaar` (`Eigenaar`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `verzinzelf3`
    FOREIGN KEY (`Huisnr` , `StraatID`)
    REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Meting`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Meting` (
  `Teamnr` INT NOT NULL,
  `Plant` VARCHAR(45) NOT NULL,
  `Meetsoort` VARCHAR(45) NULL,
  PRIMARY KEY (`Teamnr`, `Plant`),
  INDEX `verzinzelf1_idx` (`Plant` ASC) VISIBLE,
  INDEX `verzinzelf_idx` (`Teamnr` ASC) VISIBLE,
  CONSTRAINT `verzinzelf`
    FOREIGN KEY (`Teamnr`)
    REFERENCES `mydb`.`Team` (`Teamnr`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `verzinzelf1`
    FOREIGN KEY (`Plant`)
    REFERENCES `mydb`.`Plant` (`Plant beschrijving`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

And here you have a **picture** of my **ERD**

以及完整的错误消息:

Executing SQL script in server

ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'straatid' for constraint 'verzinzelf3' in the referenced table 'locatie'
SQL Code:
        -- -----------------------------------------------------
        -- Table `mydb`.`Plant`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mydb`.`Plant` (
          `Plant beschrijving` VARCHAR(45) NOT NULL,
          `Kaartlokatie` VARCHAR(45) NOT NULL,
          `Oppervlakte` VARCHAR(45) NOT NULL,
          `Eigenaar` INT NOT NULL,
          `Huisnr` VARCHAR(45) NOT NULL,
          `StraatID` VARCHAR(45) NOT NULL,
          PRIMARY KEY (`Plant beschrijving`, `Kaartlokatie`, `Oppervlakte`),
          INDEX `verzinzelf4_idx` (`Eigenaar` ASC) VISIBLE,
          INDEX `verzinzelf3_idx` (`Huisnr` ASC, `StraatID` ASC) VISIBLE,
          CONSTRAINT `verzinzelf4`
            FOREIGN KEY (`Eigenaar`)
            REFERENCES `mydb`.`Eigenaar` (`Eigenaar`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `verzinzelf3`
            FOREIGN KEY (`Huisnr` , `StraatID`)
            REFERENCES `mydb`.`Locatie` (`Huisnr` , `StraatID`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

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

Fetching back view definitions in final form.
Nothing to fetch

0 个答案:

没有答案