0

enter image description here

I want to forward engineer my er diagram to physical database.I have this error, I tried different ways to solve it but still no luck. Can someone Please help me. Here is the error message:

Executing SQL script in server ERROR: Error 1215: Cannot add foreign key constraint

SQL Code:


-- Table `mydb`.`Guest`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Guest` (
  `Location` VARCHAR(45) NOT NULL,
  `User_KexinM_Email` INT NOT NULL,
  PRIMARY KEY (`User_KexinM_Email`),
  CONSTRAINT `fk_Guest_User_KexinM1`
    FOREIGN KEY (`User_KexinM_Email`)
    REFERENCES `mydb`.`User_KexinM` (`Email`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

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

Fetching back view definitions in final form. Nothing to fetch

Samuil Petrov
  • 542
  • 1
  • 13
  • 24
  • You probably have a foreign key `fk_Guest_User_KexinM1` already from some earlier attempts. Try to rename it to e.g. `fk_Guest_User_KexinM2` or something. You may want to add the script code for `User_KexinM`, although the workbench will very likely do it correctly. – Solarflare Sep 11 '17 at 18:12
  • Possible duplicate of [MySQL Error 1215: Cannot add foreign key constraint](https://stackoverflow.com/questions/16969060/mysql-error-1215-cannot-add-foreign-key-constraint) – PayteR Sep 11 '17 at 22:42

0 Answers0