SQLSTATE 23502 ERROR Class 23: Integrity Constraint Violation

not_null_violation null value in column “…” violates not-null constraint (generated always) — 23502

PostgreSQL error “null value in column … violates not-null constraint (generated always) — 23502” (SQLSTATE 23502): what it means, common causes, and how to fix it.

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

Diagnostic Queries

Symptoms

A row supplied NULL for a column declared NOT NULL (commonly an identity/required column). PostgreSQL raises SQLSTATE 23502 (not_null_violation).

  • A NOT NULL column received a NULL value.
  • Common with identity columns set to OVERRIDING incorrectly, or missing values.
  • The DETAIL line shows the failing row.

What the server log shows

ERROR:  null value in column "id" of relation "orders" violates not-null constraint
DETAIL:  Failing row contains (null, 2024-01-01, 42.00).

Why PostgreSQL raises this — what the manual says

Section 5.5.2 Not-Null Constraints:

“A not-null constraint simply specifies that a column must not assume the null value.”

A NOT NULL column rejects NULLs. Inserting/updating a row that leaves the column NULL (no value, an explicit NULL, or a misused identity override) violates the constraint, so PostgreSQL reports 23502.

Common causes

  • Omitting a required column without a default.
  • Explicitly inserting NULL into a NOT NULL column.
  • Misusing OVERRIDING SYSTEM VALUE or feeding NULL to an identity column.

How to fix it

  1. Provide a non-null value for the column.
  2. For identity columns, let the database generate the value (don’t pass NULL).
  3. Add a sensible DEFAULT if appropriate.

Related & next steps

Reference: PostgreSQL 18 Section 5.3 “Constraints”.

Was this helpful?