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
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
-
Look at the constraint definition.
SELECT sql FROM sqlite_schema WHERE name = 'products';
-
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.
-
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
SQLITE_CONSTRAINTconstraint failed23514PostgreSQL: check constraint violation3819MySQL: Check constraint is violated547SQL Server: Statement conflicted with a constraint
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_ABORT_ROLLBACKstatement aborted by ROLLBACKSQLITE_BUSY_SNAPSHOTstale read can't become a writeSQLITE_IOERR_SHORT_READread returned fewer bytesSQLITE_CANTOPEN_ISDIRthe path is a directorySQLITE_BUSY_TIMEOUTblocking file lock timed out
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.