1215: Cannot add foreign key constraint
MySQLWhat does it mean?
The foreign key constraint being defined cannot be created; MySQL cannot add the constraint.
Why does it happen?
Data type/length/signedness (signed-unsigned) or character set/collation mismatch between the child and referenced columns, no suitable index/PRIMARY KEY on the referenced column, tables using different storage engines (one is MyISAM) or the referenced table not existing yet.
How to fix it
Make sure the column types on both sides are EXACTLY the same (e.g. both INT UNSIGNED). Verify that the referenced column is backed by an index (usually PRIMARY KEY or UNIQUE). Make sure both tables are InnoDB. Use the same charset/collation for string keys. For details: SHOW ENGINE INNODB STATUS (LATEST FOREIGN KEY ERROR).
More from this engine
- 2003Can't connect to MySQL server (TCP/IP)
- 2006MySQL server has gone away
- 1114The table is full
- 1451Cannot delete or update a parent row: a foreign key constraint fails
- 1452Cannot add or update a child row: a foreign key constraint fails
- 1366Incorrect string/integer value for column
- 1044Access denied for user to database