null value in column “…” of relation “…” violates not-null constraint

SQLSTATE 23502 condition not_null_violation class 23 — Integrity Constraint Violation severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A row being inserted or updated left a NOT NULL column empty. PostgreSQL names the column and table and shows the failing row in the DETAIL line.

What the server log shows

ERROR:  null value in column "email" of relation "users" violates not-null constraint
DETAIL:  Failing row contains (42, null, 2026-01-01).
STATEMENT:  INSERT INTO users (id, created_at) VALUES (42, now());

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.”

When a write produces a row whose NOT NULL column holds NULL — because the column was omitted and has no default, or was set to NULL explicitly — the constraint fails with 23502 and the whole statement rolls back.

Common causes

How to fix it

  1. Provide a value for the column in every insert/update.
  2. Add a sensible DEFAULT: ALTER TABLE users ALTER COLUMN created_at SET DEFAULT now();.
  3. Fix the application mapping so the field is always populated.
  4. If the column should allow blanks, drop the constraint: ALTER TABLE users ALTER COLUMN email DROP NOT NULL;.

Related & next steps

Reference: PostgreSQL 18 Section 5.4.2 “Not-Null Constraints”.