Laravel migration: SQLSTATE[HY000]: General error: 1005 Can't create table (errno: 150 "Foreign key constraint is incorrectly formed")
MySQL can't create the foreign key because column types, order or engines don't match the referenced table.
Foreign key constraint is incorrectly formedSQLSTATE[HY000]: General error: 1005 Can't create table (errno: 150)errno: 150 Foreign key constraint is incorrectly formedGeneral error: 3780 Referencing column and referenced column are incompatible1215 Cannot add foreign key constraint Meaning
The foreign column must exactly match the referenced column's type, size and signedness (unsignedBigInteger vs bigIncrements in Laravel 5.8+). The referenced table must exist first (migration order), and both must be InnoDB. Use foreignId('user_id')->constrained().
Common causes
- Referenced table created in a later migration
- Type mismatch (integer vs bigInteger, signed vs unsigned)
- MyISAM vs InnoDB engines
- Collation mismatch
- Referenced column not indexed/primary
⚡ Quick fix
- Use
$table->foreignId('user_id')->constrained()->cascadeOnDelete(); - Rename migration timestamps to run parents first
- Match types and collation exactly
Detailed fix by platform
Laravel
php artisan migrate:statusto confirm order;SHOW CREATE TABLE users;to inspect types
How to diagnose
- Order — Parent migrated first?
- Types — Identical?
- Engine — InnoDB?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026