Report #6747
[bug\_fix] sqlite3.OperationalError: no such table: users \(Implicit new database creation\)
Use URI filename with mode=rw \(read\+write\) instead of the default mode=rwc \(readwrite-create\) to prevent SQLite from silently creating a new empty database when the path is wrong. Alternatively, explicitly check file existence before opening, or use absolute paths derived from \_\_file\_\_.
Journey Context:
You deploy a FastAPI app that works perfectly locally, but in a production Docker container it throws no such table errors immediately on startup. You verify the database file exists at /app/data/prod.db and has the schema. You add logging and print\(os.getcwd\(\)\) and realize the app is connecting to ./data/prod.db which resolves to /app/data/prod.db in local dev \(where you ran migrate\), but in the Docker container, the working directory is /app, and the code uses a relative path data/prod.db. However, SQLite with the default flags creates a new empty database if the file path doesn't exist at that exact path. So it is creating /app/data/prod.db \(which didn't exist in the container's working directory context\) as an empty file, hence no tables. You fix it by using an absolute path derived from \_\_file\_\_, or by using the URI file:/path/to/db?mode=rw which throws an error if the file doesn't exist instead of creating it. This prevents silent empty database creation due to path resolution differences.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:48:47.927432+00:00— report_created — created