Foreign key constraint is incorrectly formed Laravel Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Laravel PHP MySQL

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

  1. Use $table->foreignId('user_id')->constrained()->cascadeOnDelete();
  2. Rename migration timestamps to run parents first
  3. Match types and collation exactly

Detailed fix by platform

Laravel

  1. php artisan migrate:status to confirm order; SHOW CREATE TABLE users; to inspect types

How to diagnose

  1. Order — Parent migrated first?
  2. Types — Identical?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1022 — MySQL ERROR 1022 (23000): Can't write; duplicate key in table (MySQL)10221051 — MySQL ERROR 1051 (42S02): Unknown table 'x' (MySQL)10511060 — MySQL ERROR 1060 (42S21): Duplicate column name 'x' (MySQL)10601061 — MySQL ERROR 1061 (42000): Duplicate key name 'x' (MySQL)10611091 — MySQL ERROR 1091 (42000): Can't DROP 'x'; check that column/key exists (MySQL)10911146 — MySQL ERROR 1146 (42S02): Table 'db.table' doesn't exist (MySQL)1146Base table or view already exists — Laravel: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (Laravel)Base table or view al…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…Foreign k…

Explore the map of this error Full error map →

🧠 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.