# sqlite3.OperationalError: attempt to write a readonly database

**Code:** `readonly database` · **Category:** SQL · **Seen on:** SQL

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

## 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.

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/sqlite-attempt-to-write-a-readonly-database)
