ERROR: null value in column "x" of relation "y" violates not-null constraint

An INSERT/UPDATE put NULL into a NOT NULL column.

Seen on: PostgreSQL

Meaning

The DETAIL line shows the failing row. Missing input fields, ORM attributes not set, or a new NOT NULL column without a default are typical.

Common causes

  • Required field missing from input
  • New NOT NULL column added without DEFAULT on existing rows
  • Explicit NULL instead of omitting the column
  • id column without a sequence/identity

⚡ Quick fix

  1. Validate required fields
  2. Add a DEFAULT, backfill, then set NOT NULL
  3. Use GENERATED ALWAYS AS IDENTITY for ids

Detailed fix by platform

PostgreSQL

  1. ALTER TABLE users ADD COLUMN status text NOT NULL DEFAULT 'active';

How to diagnose

  1. Column — Which one?
  2. Row — DETAIL failing row

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.