// SQLite error reference

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
Error message
NOT NULL constraint failed: users.name

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 INSERT column 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 NULL column in a table rebuild without filling it for existing rows.

How to fix it

  1. Supply a value for the column, or give it a default.

    INSERT INTO users (email, name) VALUES ('[email protected]', 'Ada');
  2. Check which columns are required.

    PRAGMA table_info(users);  -- notnull = 1, dflt_value
  3. 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

More extended result codes errors

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.

// fewer errors, faster fixes

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.