PostgreSQL error: null value violates not-null constraint

ERROR:  null value in column "email" of relation "users" violates not-null constraint
DETAIL:  Failing row contains (42, null, Alice, 2026-07-09 10:12:00).

The write would have left a NOT NULL column empty, so PostgreSQL rejected it. The DETAIL line shows the entire failing row, with values in the table's column order — line it up against \d output and you can see exactly what arrived.

What this error means

One mechanism here surprises almost everyone at some point: column defaults apply only when the column is omitted from the INSERT (or explicitly given the DEFAULT keyword). An INSERT that lists the column and passes NULL means NULL — the default does not kick in. ORMs that serialize every mapped field, sending null for unset ones, silently disable your database defaults this way.

Common causes

How to diagnose it

\d users   -- quali colonne sono NOT NULL, quali hanno un DEFAULT

Map the DETAIL row onto the column list to identify the offending field, then find who produced the NULL: application payload, ORM serialization, or the input file. Logging the actual SQL the app sends settles the "but we set a default!" conversations quickly.

How to fix it

🔍 Remember: this error aborts the transaction — see current transaction is aborted if you're catching and continuing.