readonly database 🗃️ SQL

sqlite3.OperationalError: attempt to write a readonly database

The process can’t write to the SQLite file or its directory.

Seen on: SQL

Meaning

SQLite needs write access to the file and the folder (for journal/WAL files). Web servers running as www-data, read-only container layers and app bundles cause it.

Common causes

  • File owned by another user
  • Directory not writable (journal can’t be created)
  • Read-only filesystem/container
  • Opened with mode=ro

⚡ Quick fix

  1. chown the file and its directory to the app user
  2. Store the DB on a writable volume
  3. Check open flags/URI

Detailed fix by platform

Linux

  1. sudo chown www-data:www-data /var/www/app/db /var/www/app/db/app.sqlite3

How to diagnose

  1. Permissions — File and directory writable by the app user?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.