SQLite "Datatype Mismatch" (Error 20): Type Affinity and Strict Tables
By Sharon Ben-Moshe · September 26, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Understand SQLite Error 20 (datatype mismatch). Learn how SQLite type affinity, CHECK constraints, and STRICT tables enforce data integrity.
Quick answer
SQLite Error 20 (SQLITE_MISMATCH / datatype mismatch) occurs when a value violates a column's explicit type constraint. While traditional SQLite tables use dynamic type affinity (storing text in integer columns without complaint), STRICT tables (introduced in SQLite 3.37.0) and CHECK constraints strictly reject incompatible types like inserting text into an INT column.
FAQs
Why does SQLite normally allow inserting text into an INTEGER column?
Traditional SQLite uses dynamic typing with 'type affinity'. The declared column type is merely a hint; SQLite attempts to convert the value, but if conversion fails, it happily stores the string as TEXT without throwing an error.
What are SQLite STRICT tables?
Introduced in SQLite 3.37.0 (November 2021), the `STRICT` table option disables type affinity. Any insert that does not match the declared type (INT, REAL, TEXT, BLOB, ANY) fails with SQLITE_MISMATCH (code 20).
How do I create a STRICT table in SQLite?
Append the keyword `STRICT` after the closing parenthesis of the CREATE TABLE statement: `CREATE TABLE users (id INT PRIMARY KEY, name TEXT) STRICT;`.
Can a CHECK constraint cause SQLITE_MISMATCH?
Yes. A constraint like `CHECK (typeof(age) == 'integer')` will reject float or text inputs with a constraint or mismatch error.
Keep reading
Fix BigQuery "Unrecognized Name" Error: Scoping and Syntax Rules
By Sharon Ben-Moshe · Sep 29, 2026
Fix Google BigQuery's "Unrecognized name: column" error. Learn alias visibility rules across WHERE and QUALIFY, case sensitivity, and struct unnesting.
Read postPostgreSQL statement_timeout (Error 57014): Causes and Prevention
By Sharon Ben-Moshe · Sep 23, 2026
Fix PostgreSQL Error 57014: canceling statement due to statement_timeout. Learn how to tune query plans, configure timeouts per session, and avoid lock waits.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.