SQLSTATE 23503 ERROR Class 23: Integrity Constraint Violation

foreign_key_violation update or delete on table “…” violates foreign key constraint (restrict) — 23503

PostgreSQL error “update or delete on table … violates foreign key constraint (restrict) — 23503” (SQLSTATE 23503): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

An UPDATE or DELETE on a referenced (parent) row was blocked because dependent (child) rows still reference it under a RESTRICT/NO ACTION foreign key. PostgreSQL raises SQLSTATE 23503 (foreign_key_violation).

  • Deleting/updating a parent row that has children.
  • The FK uses RESTRICT or NO ACTION (no cascade).
  • The DETAIL line names the referencing table and key.

What the server log shows

ERROR:  update or delete on table "customers" violates foreign key constraint "orders_customer_fk" on table "orders"
DETAIL:  Key (id)=(42) is still referenced from table "orders".

Why PostgreSQL raises this — what the manual says

Section 5.5.5 Foreign Keys:

“RESTRICT is a stricter setting than NO ACTION. It prevents deletion of a referenced row.”

A foreign key with RESTRICT/NO ACTION forbids removing or re-keying a parent row while child rows reference it. Such an operation would orphan the children, so PostgreSQL reports 23503.

Common causes

  • Deleting a parent that still has dependent rows.
  • Updating a referenced key value with children present.
  • Expecting cascade behaviour where the FK uses RESTRICT/NO ACTION.

How to fix it

  1. Delete/repoint the child rows first, then the parent.
  2. Define the FK with ON DELETE CASCADE/ON UPDATE CASCADE if that’s intended.
  3. Use a soft-delete or reassign children before removing the parent.

Related & next steps

Reference: PostgreSQL 18 Section 5.4 “Constraints”.

Was this helpful?