pgref.dev/sqlite/errors/SQLITE_CONSTRAINT_CHECK
SQLITE_CONSTRAINT_CHECKERRORTier 2 — Caution⚠️ MEDIUM confidence

CHECK constraint failed

Category: ConstraintVersions: 3.8.0+

🔴 Production Risk Error

Medium — write fails; transaction is rolled back unless ON CONFLICT handles it.

What this means

SQLITE_CONSTRAINT_CHECK (275) is an extended result code returned when a CHECK constraint is violated during an INSERT or UPDATE operation.

Why it happens

  1. 1Inserting or updating a row where the value does not satisfy a CHECK constraint.
  2. 2Application logic allowing out-of-range values to reach the database.

How to reproduce

INSERT or UPDATE violating a CHECK constraint.

trigger — this will ERROR
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE products(price REAL CHECK(price > 0))')
try:
    conn.execute('INSERT INTO products VALUES(-5.0)')
except sqlite3.IntegrityError as e:
    print(e)  # CHECK constraint failed: price > 0
sqlite3.IntegrityError: CHECK constraint failed: price > 0

Fix 1

Why this works

Validate data before INSERT: assert price > 0, "Price must be positive"

Fix 2

Why this works

Use ON CONFLICT IGNORE or ON CONFLICT REPLACE if invalid values should be discarded.

Fix 3

Why this works

Review and tighten application-level validation.

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#constraint_check

🔧 Source ref: sqlite3.h — SQLITE_CONSTRAINT_CHECK = 275

📖 Further reading: SQLite CHECK constraints

Confidence assessment

⚠️ MEDIUM confidence

Stable.

See also

⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →