// SQLite error reference

SQLITE_SCHEMA: database schema has changed

A prepared statement became invalid because the schema changed after it was prepared, and SQLite could not re-prepare it.

Result code
SQLITE_SCHEMA
Name
17
Category
Primary result codes
Error message
database schema has changed

What it means

SQLITE_SCHEMA (17) means the schema changed between preparing a statement and running it, for example another connection added an index or altered a table. Statements prepared with sqlite3_prepare_v2() (what nearly every modern binding uses) are re-prepared automatically, up to 50 times by default, so you only see this error with the legacy sqlite3_prepare() or when re-preparing keeps failing.

Common causes

  • Using the legacy sqlite3_prepare() interface, which doesn't re-prepare on schema changes.
  • Another connection changing the schema constantly while statements are being prepared and run.
  • A schema change that makes the re-prepared statement invalid, for example dropping a column it uses.

How to fix it

  1. Prepare statements with sqlite3_prepare_v2() or sqlite3_prepare_v3() so SQLite re-prepares them for you.

  2. If you get this from a statement cache, finalize the cached statement and prepare it again after a schema change.

  3. Run schema migrations while the application is idle, not while other connections are executing statements.

Related errors

More primary 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.