So it turns out my foreign key constraints were all messed up. I had the relationships backwards. Instead of having the foreign keys reference the primary keys, I was having the primary keys BE the foreign keys referencing the non unique columns. I reversed that, and it worked.
MYSQL ERROR: Error 1215: Cannot add foreign key constraint
-
15-10-2022 - |
Frage
I'm trying to forward engineer my ERD into scheme in workbench 6.0 but I'm getting this error. I've checked all column types and they're the same. I looked through similar questions here but still cannot find an answer. Here's the error log:
xecuting SQL script in server
ERROR: Error 1215: Cannot add foreign key constraint
-- -----------------------------------------------------
-- Table `proj`.`employee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `proj`.`employee` (
`employee_id` INT NOT NULL,
`position_id` INT NOT NULL,
PRIMARY KEY (`employee_id`),
CONSTRAINT `fk_employee_employee_history1`
FOREIGN KEY (`employee_id`)
REFERENCES `proj`.`employee_history` (`employee_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_equipment_rentals1`
FOREIGN KEY (`employee_id`)
REFERENCES `proj`.`equipment_rentals` (`handling_employee_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_scheduled_trips1`
FOREIGN KEY (`employee_id`)
REFERENCES `proj`.`scheduled_trips` (`leader`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_scheduled_trips2`
FOREIGN KEY (`employee_id`)
REFERENCES `proj`.`scheduled_trips` (`assistant`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 8 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow