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.
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 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
- Add validation
unique:users,emailand usefirstOrCreate()/upsert() - Create parents first; cascade deletes (
onDelete('cascade')) if intended - Catch
QueryExceptionand readerrorInfo[1]
Detailed fix by platform
Laravel
User::firstOrCreate(['email' => $email], ['name' => $name]);
How to diagnose
- Code — 1062, 1452, 1048, 1451?
- Index — Which key?
- 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:
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