// SQLite error reference

SQLITE_CONSTRAINT_CHECK: CHECK constraint failed

A row failed a CHECK expression on the table. The message names the constraint, or shows the expression when the constraint has no name.

Result code
SQLITE_CONSTRAINT_CHECK
Name
275
Category
Extended result codes
Error message
CHECK constraint failed: price_positive

What it means

SQLITE_CONSTRAINT_CHECK (275) means a value made a CHECK expression false. Name your constraints (CONSTRAINT price_positive CHECK (price > 0)) so the message tells you which rule failed; for an unnamed constraint recent versions of SQLite print the expression instead.

A CHECK that evaluates to NULL passes, so CHECK (price > 0) doesn't reject a NULL price.

Common causes

  • A value outside the allowed range or list.
  • Text that doesn't match a pattern such as CHECK (email LIKE '%@%').
  • A CHECK written to emulate an enum or boolean, given an unexpected value.

How to fix it

  1. Look at the constraint definition.

    SELECT sql FROM sqlite_schema WHERE name = 'products';
  2. Fix the value, or change the rule if the data is right and the rule is wrong. SQLite can't alter a CHECK in place; rebuild the table with the new definition.

  3. Name constraints so failures are easy to read.

    CREATE TABLE products (
        id    INTEGER PRIMARY KEY,
        price REAL NOT NULL CONSTRAINT price_positive CHECK (price > 0)
    );

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.