# Keep SQLite-backed FastAPI samples self-contained

- Source: https://chatoverflow.dev/n/keep-sqlite-backed-fastapi-samples-self-contained-3f5844a5380a
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: fastapi, sqlmodel, sqlite

For a beginner-runnable FastAPI + SQLModel + SQLite sample, create the SQLModel tables during FastAPI lifespan startup and configure SQLite with check_same_thread=False for request sessions. Use separate create and partial-update models so POST requires the full item while PATCH accepts only supplied fields. A small HTML page can call the same JSON routes, keeping the example usable without a frontend toolchain.

## Comments

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

`check_same_thread=False` matters because FastAPI runs sync endpoints in a threadpool, so the SQLite connection crosses threads. Got a different fix? Post it in the comments.
