SQLSTATE[23000]: Integrity constraint violation Laravel Origin: Application & API Last updated 4 Nov 2026

Laravel: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'x@example.com' for key 'users_email_unique'

The query violated a database constraint — a duplicate value in a unique column or a missing/blocked foreign key.

Exact message you may see SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entryIntegrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsSQLSTATE[23000]: Integrity constraint violation: 1048 Column cannot be nullIntegrity constraint violation: 1451 Cannot delete or update a parent rowSQLSTATE[23000] Laravel
Seen on: Laravel PHP MySQL

Meaning

1062 = duplicate entry (unique index), 1452 = foreign key parent row missing, 1048 = column cannot be null, 1451 = cannot delete a row referenced elsewhere. Validate with unique: rules, use firstOrCreate/upsert, and check relations before insert/delete.

Common causes

  • Duplicate value in a unique column
  • Foreign key points to a non-existent parent (1452)
  • Inserting null into a NOT NULL column (1048)
  • Deleting a parent that has children (1451)
  • Race condition on concurrent inserts

⚡ Quick fix

  1. Add validation unique:users,email and use firstOrCreate() / upsert()
  2. Create parents first; cascade deletes (onDelete('cascade')) if intended
  3. Catch QueryException and read errorInfo[1]

Detailed fix by platform

Laravel

  1. User::firstOrCreate(['email' => $email], ['name' => $name]);

How to diagnose

  1. Code — 1062, 1452, 1048, 1451?
  2. Index — Which key?
  3. Flow — Concurrent inserts?

🔧 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):

1048 — MySQL ERROR 1048 (23000): Column 'x' cannot be null (MySQL)10481062 — MySQL ERROR 1062 (23000): Duplicate entry for key (MySQL)10621451 — MySQL ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (MySQL)14511452 — MySQL ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (MySQL)1452Base 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…Foreign key constraint is incorrectly formed — Laravel migration: SQLSTATE[HY000]: General error: 1005 Can't create table (errno: 150 "Foreign key constraint is incorrectly formed") (Laravel)Foreign key constrain…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…One or more database tables are unavailable — WordPress: One or more database tables are unavailable. The database may need to be repaired. (WordPress)One or more database …SQLSTATE[…

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.