SQLSTATE 23502Severity lowLab verified

Incident brief

Null value in column violates not-null constraint

A column was declared NOT NULL, and an INSERT or UPDATE tried to leave it null anyway. PostgreSQL rejects the row before it is ever stored.

Reproduced on PostgreSQL 16.14Verified 2026-07-15 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Null value in column violates not-null constraint
What triggers it
Create a table with a column marked NOT NULL.
The fix
Provide a real value for the column on every INSERT/UPDATE.
Proof
Reproduced on PostgreSQL 16.14 → The INSERT that left email NULL was rejected with SQLSTATE 23502 and the row was never stored — the table stayed empty.

The fix

What to do right now

The immediate, application-level response to this error.

  • Provide a real value for the column on every INSERT/UPDATE.
  • If a value is genuinely optional, remove the NOT NULL constraint instead of forcing a placeholder.
  • Do not rely on a column DEFAULT to fill in NULL — a DEFAULT of NULL is still NULL, and NOT NULL still rejects it.
Fix — SQL
CREATE TABLE billing.customers (
  id integer primary key,
  email text NOT NULL
);

-- provide a real value instead of NULL
INSERT INTO billing.customers (id, email) VALUES (1, 'a@example.com');

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-15 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed