23503 PostgreSQL Origin: Data Last updated 14 Oct 2026

ERROR: insert or update on table "x" violates foreign key constraint "fk" — Key (user_id)=(5) is not present in table "users"

The row references a parent row that doesn’t exist.

Exact message you may see violates foreign key constraintis not present in table
Seen on: PostgreSQL

Meaning

The DETAIL line names the missing key. Inserting children before parents, deleted parents, or wrong ids from the client.

Common causes

  • Parent row doesn’t exist (wrong id)
  • Insert order wrong in seeds/imports
  • Parent deleted concurrently

⚡ Quick fix

  1. Insert parents first
  2. Validate the referenced id exists
  3. Defer constraints within a transaction for bulk loads (DEFERRABLE)

Detailed fix by platform

PostgreSQL

  1. SELECT 1 FROM users WHERE id = 5;

How to diagnose

  1. Key — DETAIL shows which key?
  2. Order — Parent inserted first?

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

1451 — 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)145223502 — ERROR: null value in column "x" of relation "y" violates not-null constraint (PostgreSQL)2350223503 parent — ERROR: update or delete on table "users" violates foreign key constraint on table "orders" — Key (id)=(5) is still referenced (PostgreSQL)23503 parent23505 — PostgreSQL: ERROR: duplicate key value violates unique constraint (PostgreSQL)2350523514 — ERROR: new row for relation "x" violates check constraint "y" (PostgreSQL)2351442P10 — ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification (PostgreSQL)42P10ALREADY_EXISTS — API Error: Resource already exists (ALREADY_EXISTS / resource_already_exists / 409) (API)ALREADY_EXISTS23503

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.