MySQL ERROR 1005 (HY000): Can't create table (errno: 150 "Foreign key constraint is incorrectly formed")
A foreign key definition is invalid — the referenced column’s type, index or charset doesn’t match.
Seen on:
MySQL
Meaning
FK columns must have identical types (including UNSIGNED and length), the referenced column must be indexed (usually a primary/unique key), and both tables must be InnoDB with compatible collations.
Common causes
- INT vs INT UNSIGNED / BIGINT mismatch
- Referenced column not indexed
- Different charset/collation on string keys
- Referenced table doesn’t exist yet (creation order)
- MyISAM table
⚡ Quick fix
- Make column definitions identical
- Index the referenced column
- Create parent tables first
- Run SHOW ENGINE INNODB STATUS for the detailed reason
Detailed fix by platform
MySQL
SHOW ENGINE INNODB STATUS\G -- see LATEST FOREIGN KEY ERROR
How to diagnose
- Types — Child vs parent column definitions
- Index — Referenced column indexed?
- Order — Parent created first?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026