DBAtlas · Database operations atlas

23502: not_null_violation

PostgreSQL

What does it mean?

An attempt was made to insert NULL into a column with a NOT NULL constraint, or to set that column to NULL.

Why does it happen?

Omitting a required column from the INSERT, explicitly assigning NULL, the column having no DEFAULT, or an empty/missing value coming from the application.

How to fix it

Supply a valid value for the column or define a sensible DEFAULT on it: ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT value. If the column does not really need to be mandatory, drop the constraint: ALTER TABLE my_table ALTER COLUMN my_column DROP NOT NULL. Add missing-data validation in the application layer.

Open in DBAtlas →

More from this engine