Report #96415
[bug\_fix] attempt to write a readonly database \(SQLITE\_READONLY\)
Ensure the directory containing the database file is writable by the process, as SQLite needs to create \`-wal\` and \`-shm\` files there when WAL mode is enabled, even if the \`.db\` file itself is writable.
Journey Context:
Your Django app works on your local Mac, but when deployed to a Linux production server with the SQLite file mounted at \`/opt/app/data/db.sqlite3\`, it crashes with \`attempt to write a readonly database\`. You check \`ls -l\` and the file is \`-rw-r--r--\` owned by the web user. You can \`echo test >> /opt/app/data/db.sqlite3\` as that user. Confused, you check if the filesystem is mounted read-only, but it's not. You then notice in the error trace that it's trying to write to the database during a POST request. You check \`PRAGMA journal\_mode;\` and it returns \`wal\`. Suddenly it clicks: in WAL mode, SQLite writes to the \`-wal\` file. You check if \`/opt/app/data/db.sqlite3-wal\` exists; it doesn't. You try \`touch /opt/app/data/testfile\` as the web user and get 'Permission denied'. The directory \`/opt/app/data\` is owned by root with \`drwxr-xr-x\`. Even though the \`.db\` file is writable, the directory is not, so SQLite cannot create the WAL files. You run \`chown www-data:www-data /opt/app/data\` and the error disappears.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:24:55.552994+00:00— report_created — created