1451 MySQL Origin: Data Last updated 12 Oct 2026

MySQL ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails

You tried to delete/update a row that other rows still reference.

Exact message you may see Cannot delete or update a parent row
Seen on: MySQL

Meaning

Child rows exist with a foreign key pointing to this parent, and the FK doesn’t cascade.

Common causes

  • Deleting a user/order that still has related rows
  • FK without ON DELETE CASCADE/SET NULL

⚡ Quick fix

  1. Delete or reassign child rows first
  2. Define ON DELETE CASCADE / SET NULL where appropriate
  3. Soft-delete instead

Detailed fix by platform

MySQL

  1. ALTER TABLE orders ADD CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;

How to diagnose

  1. Constraint — Which child table?
  2. Intent — Should children be removed?

🔧 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: Data. Errors that are often confused with or caused by this one (click to open):

1005 — MySQL ERROR 1005 (HY000): Can't create table (errno: 150 "Foreign key constraint is incorrectly formed") (MySQL)10051022 — MySQL ERROR 1022 (23000): Can't write; duplicate key in table (MySQL)10221048 — MySQL ERROR 1048 (23000): Column 'x' cannot be null (MySQL)10481062 — MySQL ERROR 1062 (23000): Duplicate entry for key (MySQL)10621452 — MySQL ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (MySQL)145223503 — ERROR: insert or update on table "x" violates foreign key constraint "fk" — Key (user_id)=(5) is not present in table "users" (PostgreSQL)2350323503 parent — ERROR: update or delete on table "users" violates foreign key constraint on table "orders" — Key (id)=(5) is still referenced (PostgreSQL)23503 parentALREADY_EXISTS — API Error: Resource already exists (ALREADY_EXISTS / resource_already_exists / 409) (API)ALREADY_EXISTS1451

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.