LMSouq
database Open

MySQL Error 1215: Cannot add foreign key constraint

RO
Robert B
1 month ago
3 views
Problem Description
I am trying to forward engineer my new schema onto my database server, but I get this error. Everything I've found has said to either set the database engine to InnoDB or to make sure the keys I'm trying to use as a foreign key are primary keys in their own tables. I have done these things. What else can I do? ```lang-none Executing SQL script in server ERROR: Error 1215: Cannot add foreign key constraint -- ----------------------------------------------------- -- Table `Alternative_Pathways`.`Clients_has_Staff` -- ----------------------------------------------------- ``` CREATE TABLE IF NOT EXISTS `Alternative_Pathways`.`Clients_has_Staff` ( `Clients_Case_Number` INT NOT NULL , `Staff_Emp_ID` INT NOT NULL , PRIMARY KEY (`Clients_Case_Number`, `Staff_Emp_ID`) , INDEX `fk_Clients_has_Staff_Staff1_idx` (`Staff_Emp_ID` ASC) , INDEX `fk_Clients_has_Staff_Clients_idx` (`Clients_Case_Number` ASC) , CONSTRAINT `fk_Clients_has_Staff_Clients` FOREIGN KEY (`Clients_Case_Number` ) REFERENCES `Alternative_Pathways`.`Clients` (`Case_Number` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_Clients_has_Staff_Staff1` FOREIGN KEY (`Staff_Emp_ID` ) REFERENCES `Alternative_Pathways`.`Staff` (`Emp_ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB SQL script execution finished: statements: 7 succeeded, 1 failed SQL for the parent tables: CREATE TABLE IF NOT EXISTS `Alternative_Pathways`.`Clients` ( `Case_Number` INT NOT NULL , `First_Name` CHAR(10) NULL , `Middle_Name` CHAR(10) NULL , `Last_Name` CHAR(10) NULL , `Address` CHAR(50) NULL , `Phone_Number` INT(10) NULL , PRIMARY KEY (`Case_Number`) ) ENGINE = InnoDB CREATE TABLE IF NOT EXISTS `Alternative_Pathways`.`Staff` ( `Emp_ID` INT NOT NULL , `First_Name` CHAR(10) NULL , `Middle_Name` CHAR(10) NULL , `Last_Name` CHAR(10) NULL , PRIMARY KEY (`Emp_ID`) ) ENGINE = InnoDB

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base