SQLITE_CONSTRAINT_CHECK
SQLiteERRORCommonConstraint ViolationHIGH confidence

CHECK constraint failed

What this means

SQLITE_CONSTRAINT_CHECK (extended code 275) is raised when an inserted or updated value fails a CHECK constraint expression defined on the table or column. SQLite evaluates CHECK expressions as SQL expressions — any expression that returns FALSE or a value that is not truthy causes this error.

Why it happens
  1. 1Inserting a value that violates an inline column CHECK expression (e.g., CHECK(price > 0))
  2. 2Inserting a row that violates a table-level CHECK constraint involving multiple columns
How to reproduce

A negative price is inserted into a column with a CHECK(price > 0) constraint.

trigger — this will error
trigger — this will error
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE products (id INTEGER PRIMARY KEY, price REAL CHECK(price > 0))')
conn.execute('INSERT INTO products VALUES (1, -5.0)')  # triggers CHECK violation

expected output

sqlite3.IntegrityError: CHECK constraint failed: products

Fix

Validate data before inserting

WHEN When data comes from external sources and may violate business rules.

Validate data before inserting
import sqlite3

def insert_product(conn, product_id, price):
    if price <= 0:
        raise ValueError(f"Price must be positive, got {price}")
    conn.execute('INSERT INTO products VALUES (?, ?)', (product_id, price))

conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE products (id INTEGER PRIMARY KEY, price REAL CHECK(price > 0))')
insert_product(conn, 1, 9.99)  # ok

Why this works

Application-level validation before the INSERT produces a clear, domain-specific error message rather than a generic SQLite constraint error. This also allows more complex validation logic than a SQL CHECK expression can express.

What not to do

Remove the CHECK constraint to make the insert succeed

CHECK constraints encode business invariants. Removing them allows logically invalid data (e.g., negative prices) into the database, causing downstream calculation errors.

Version notes
SQLite 3.7.16+

Extended code 275 introduced. Earlier versions return base SQLITE_CONSTRAINT.

Sources
Official documentation ↗

sqlite3.h — SQLITE_CONSTRAINT_CHECK = 275

SQLite CHECK constraints

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All SQLite errors