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.

What lands in your log

ERROR: null value in column "email" of relation "customers" violates not-null constraint

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

In 10 seconds

What triggers it
Create a table with a column marked NOT NULL.
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.

Fix

What to do right now

Application-level steps for 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
-- Table already enforces NOT NULL. Provide a real value.
INSERT INTO billing.customers (id, email) VALUES (2, '[email protected]');
SELECT id, email FROM billing.customers ORDER BY id;

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Verification

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

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops