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
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
-
Prepare statements with
sqlite3_prepare_v2()orsqlite3_prepare_v3()so SQLite re-prepares them for you. -
If you get this from a statement cache, finalize the cached statement and prepare it again after a schema change.
-
Run schema migrations while the application is idle, not while other connections are executing statements.
Related errors
More primary result codes errors
SQLITE_PERMaccess permission deniedSQLITE_ABORTquery abortedSQLITE_BUSYdatabase is lockedSQLITE_LOCKEDdatabase table is lockedSQLITE_NOMEMout of memorySQLITE_READONLYattempt to write a readonly databaseSQLITE_INTERRUPTinterruptedSQLITE_IOERRdisk I/O error
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.