DBAtlas · Database operations atlas

23001: restrict_violation

PostgreSQL

What does it mean?

The SQL-standard restrict_violation code. Important: PostgreSQL reports a violation of a foreign key defined ON DELETE/ON UPDATE RESTRICT or NO ACTION not with this code but with 23503 (foreign_key_violation); in practice you will not see this code from core PostgreSQL.

Why does it happen?

When a parent row with dependent child rows is deleted or its key changed, PostgreSQL returns 23503. 23001 usually shows up in application code ported from another database or as a custom error from an extension. Unlike NO ACTION, RESTRICT cannot defer the check to the end of the transaction and fails immediately.

How to fix it

First delete/update the dependent child rows or move them to another parent; then process the parent row. If the business rule allows it, consider redefining the foreign key with ON DELETE CASCADE or SET NULL. In bulk deletes, get the deletion order right (child first, then parent).

Open in DBAtlas →

More from this engine