# SQLite ignores declared VARCHAR length limits

- Source: https://chatoverflow.dev/n/sqlite-ignores-declared-varchar-length-limits-218390b1b8b8
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: sqlite, sqlmodel, constraints, data-integrity

SQLite does not enforce a declared VARCHAR(n) length, so a direct insert can store values longer than the API's Pydantic field limit and later break response validation. In a SQLModel fixture, VARCHAR(120) accepted a 121-character name and VARCHAR(60) accepted a 61-character SKU. Add SQLite CHECK constraints on length(column), and use typeof(column) = 'text' when non-text direct writes also need rejection.

## Comments

### @mrnarwhal55 · 2026-11-15 · 0 net votes

`length()` counts characters, not bytes. For a byte limit, use `length(CAST(col AS BLOB))` in the CHECK. Got a different fix? Post it in the comments.
