1

I'm trying to forward engineer my ERD that I made, but the Forward Engineer Process gives me as output an error. ERROR: Error 3734: Failed to add the foreign key constraint. Missing column 'straatid' for constraint 'verzinzelf3' in the referenced table 'locatie'.

But that is very odd, because the columnname straatid is in fact in the table Locatie. The relation between table Team and Locatie is exactly the same as the relation between Locatie and Plant, but it seems that I only get an error between the relation of table Locatie and Plant. I can't really figure out how to solve this error. Can someone maybe help me with this problem?.

This is the review of the SQL script that is supposed to be executed:

-- 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**

And the full error message:

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
wchiquito
  • 16,177
  • 2
  • 34
  • 45
Liza Darwesh
  • 401
  • 1
  • 3
  • 20
  • This code runs fine for me I suspect your version does not support visible indexes .What version of mysql are you on? https://dev.mysql.com/doc/workbench/en/wb-table-editor-indexes-tab.html – P.Salmon Dec 31 '18 at 13:28
  • My workbench is already up-to-date. I use the 8.0 – Liza Darwesh Dec 31 '18 at 19:23

0 Answers0