NOT NULL Constraint Violation
Error message
null value in column violates not-null constraint
Quick summary
You attempted to insert or update a row without providing a value for a column marked NOT NULL.
Why this happens
Omitting a required column from an INSERT statement
Passing null/undefined from the application for a required field
A column was changed to NOT NULL but existing rows have NULL values
Minimal example
INSERT INTO users (id) VALUES (1);
-- But 'email' is NOT NULL and was not providedINSERT INTO users (id, email) VALUES (1, 'ada@example.com');The email column is NOT NULL, so it must be provided. Adding it to the INSERT fixes the error.
How to diagnose
Read the error to identify which column requires a value
Check your INSERT or UPDATE statement — is the column provided?
Verify the application is not sending null for a required field
How to fix
Provide a value for the NOT NULL column
Add a DEFAULT value to the column if appropriate
Remove the NOT NULL constraint if the column should allow NULL
Update existing NULL values before adding the NOT NULL constraint
How to prevent
Validate required fields in your application before inserting
Use form validation to ensure users fill in required fields
Document which columns are required
Related Resources
Related Glossary
Related Lessons
- Constraints
Learn about NOT NULL constraints.