Report #8537
[bug\_fix] attempt to write a readonly database
Ensure the directory containing the SQLite database file has write permissions for the process, not just the file itself. SQLite must create temporary files \(journal, WAL, shared-memory files\) in the same directory as the database.
Journey Context:
A developer deploys a Django app using SQLite to a VPS. The app runs as \`www-data\`. The developer uploads \`db.sqlite3\` and sets permissions to 644, owned by www-data. The app works for reads, but writes \(e.g., creating a user\) throw "django.db.utils.OperationalError: attempt to write a readonly database". The developer checks \`ls -l\` and confirms www-data owns the file and it's writable. They try \`chmod 666\` to no avail. They check \`mount \| grep ' / '\` but the filesystem is not read-only. They eventually check the directory: \`ls -ld /var/www/html/\`. The directory is owned by root with 755. While www-data can read the db file, SQLite cannot create the \`-journal\` or \`-wal\` files in that directory when it tries to write. The fix is \`chown www-data:www-data /var/www/html/\` and \`chmod 755 /var/www/html/\`. After this, writes work.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:44:53.198977+00:00— report_created — created