Report #5934
[bug\_fix] SQLite attempt to write a readonly database \(SQLITE\_READONLY / error code 8\)
Ensure the Unix file permissions allow write access to the database file AND the containing directory for the process user. If using URI filenames, remove 'mode=ro'. Root cause: The process lacks write permission on either the .db file or the directory \(needed for -journal/-shm files\).
Journey Context:
A Django application is deployed to a production Ubuntu server using SQLite. The development environment works perfectly. On production, any attempt to create a user in the admin panel throws 'OperationalError: attempt to write a readonly database'. The developer first checks settings.py: DATABASES name points to '/var/www/db.sqlite3'. They check the file: ls -l /var/www/db.sqlite3 shows -rw-r--r-- 1 root root. The file is owned by root, but the Django app runs as www-data via Gunicorn. The developer runs chown www-data:www-data /var/www/db.sqlite3. The error persists. Checking the SQLite documentation, they learn that SQLite requires write access to the directory containing the database file to create the journal file \(-journal or -wal\) for atomic commits. They check the directory: ls -ld /var/www shows drwxr-xr-x 2 root root. The directory is not writable by www-data. Solution: sudo chown www-data:www-data /var/www or chmod 775 /var/www with appropriate group ownership. After changing directory permissions, the application writes successfully. The developer also realizes that using mode=ro in the URI would cause this, but that wasn't the case here.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:41:29.283266+00:00— report_created — created