Home >Database >Mysql Tutorial >Why Am I Getting MySQL Error 1215: Cannot Add Foreign Key Constraint?
In an attempt to engineer a new database schema, a user encountered the MySQL error "Error 1215: Cannot add foreign key constraint." They have already set the database engine to InnoDB and verified that the keys designated as foreign keys are primary keys in their respective tables.
The issue may stem from a difference in data types between the foreign key columns in Clients_has_Staff and the corresponding primary key columns in the parent tables (Clients and Staff).
Possible Solution:
The user should check if the following columns have the same data type in all three tables:
For example, if the parent table columns are INT UNSIGNED, the foreign key columns in Clients_has_Staff must also be INT UNSIGNED. Failure to match data types will prevent the foreign key constraint from being added successfully.
The above is the detailed content of Why Am I Getting MySQL Error 1215: Cannot Add Foreign Key Constraint?. For more information, please follow other related articles on the PHP Chinese website!