SQLITE_CONSTRAINT_NOTNULL: NOT NULL constraint failed
An INSERT or UPDATE tried to store NULL in a NOT NULL column, often because the column was left out and has no default. The message names it.
- Result code
SQLITE_CONSTRAINT_NOTNULL- Name
1299- Category
- Extended result codes
What it means
SQLITE_CONSTRAINT_NOTNULL (1299) means a NOT NULL column would have received NULL. That happens when you pass NULL explicitly, and also when an INSERT leaves out a NOT NULL column that has no DEFAULT, because the missing column gets NULL.
Common causes
- The
INSERTcolumn list leaves out a required column with no default. - The application passed NULL or None for a value it didn't have.
- Adding a
NOT NULLcolumn in a table rebuild without filling it for existing rows.
How to fix it
-
Supply a value for the column, or give it a default.
INSERT INTO users (email, name) VALUES ('[email protected]', 'Ada'); -
Check which columns are required.
PRAGMA table_info(users); -- notnull = 1, dflt_value
-
To add a required column to an existing table, give it a default so existing rows get a value.
ALTER TABLE users ADD COLUMN status TEXT NOT NULL DEFAULT 'active';
Reproduce it safely
CREATE TABLE users (email TEXT, name TEXT NOT NULL);
INSERT INTO users (email) VALUES ('a@x'); -- Runtime error: NOT NULL constraint failed: users.name (19)
Related errors
SQLITE_CONSTRAINTconstraint failed23502PostgreSQL: null value violates not-null constraint1048MySQL: Column cannot be null515SQL Server: Cannot insert the value NULL into columnORA-01400Oracle: cannot insert NULL into column
More extended result codes errors
SQLITE_ERROR_MISSING_COLLSEQno such collation sequenceSQLITE_BUSY_RECOVERYanother process is recovering the WALSQLITE_LOCKED_SHAREDCACHErecord locked in shared cacheSQLITE_CONSTRAINT_CHECKCHECK constraint failedSQLITE_ABORT_ROLLBACKstatement aborted by ROLLBACKSQLITE_BUSY_SNAPSHOTstale read can't become a writeSQLITE_IOERR_SHORT_READread returned fewer bytesSQLITE_CANTOPEN_ISDIRthe path is a directory
The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.
Work on SQLite in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.