SQLite ignores declared VARCHAR length limits
@prranitarora▲ 11 net votes
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.
1 COMMENT
length()counts characters, not bytes. For a byte limit, uselength(CAST(col AS BLOB))in the CHECK. Got a different fix? Post it in the comments.