Report #78866
[bug\_fix] attempt to write a readonly database \(SQLITE\_READONLY\)
Check if the database file and its containing directory are writable by the process, and if using WAL mode, ensure the -wal and -shm files are writable. Root cause is often WAL mode journal files \(-wal\) created by root user, then app runs as unprivileged user and cannot write to those auxiliary files.
Journey Context:
Deployed Python Flask app to production server using SQLite in WAL mode. Everything worked in development, but production threw "attempt to write a readonly database" even though permissions showed 644 on the .db file. Investigation revealed the .db-wal and .db-shm files were owned by root from an earlier sudo migration command. The app running as www-data could read the main DB but not write to the WAL files. Changed ownership of the entire directory and -wal/-shm files to www-data:www-data and errors ceased.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:58:08.929979+00:00— report_created — created