SQLITE_READONLY: attempt to write a readonly database
The connection can't write: the file or its directory isn't writable, the database was opened read-only, or SQLite can't create its journal file.
- Result code
SQLITE_READONLY- Name
8- Category
- Primary result codes
What it means
SQLITE_READONLY (8) is returned when a statement tries to change data the connection has no write permission for. Writing needs permission on the database file and also on its directory, because SQLite creates a journal (-journal) or WAL (-wal, -shm) file beside it.
Extended codes say why: SQLITE_READONLY_DIRECTORY (no permission to create the journal), SQLITE_READONLY_DBMOVED (the file was moved or deleted while open), SQLITE_READONLY_ROLLBACK (a hot journal needs rolling back but the database is read-only), and others.
Common causes
- The database file is owned by another user or mounted read-only, typical for a web server user or a file inside an app bundle.
- The directory isn't writable, so SQLite can't create the journal file even though the file itself is.
- The connection was opened read-only (
SQLITE_OPEN_READONLY,?mode=roURI, orPRAGMA query_only = ON). - The file was moved, renamed or deleted while the connection was open (
SQLITE_READONLY_DBMOVED).
How to fix it
-
Give the process write permission on the file and on its directory. On Linux and macOS check with
ls -lon both, then fix ownership or mode. -
Check whether the connection itself is read-only.
PRAGMA query_only; PRAGMA database_list;
-
Open the database read-write: drop
mode=rofrom the URI or the read-only flag from the open call. -
If the file was moved while open, close the connection and open it again at its new path.
Related errors
SQLITE_CANTOPENunable to open database fileSQLITE_PERMaccess permission deniedSQLITE_READONLY_DBMOVEDdatabase file moved while openSQLITE_READONLY_ROLLBACKhot journal can't be rolled back25006PostgreSQL: read-only SQL transaction
More primary result codes errors
SQLITE_ERRORSQL logic errorSQLITE_ABORTquery abortedSQLITE_BUSYdatabase is lockedSQLITE_LOCKEDdatabase table is lockedSQLITE_NOMEMout of memorySQLITE_INTERRUPTinterruptedSQLITE_IOERRdisk I/O errorSQLITE_CORRUPTdatabase disk image is malformed
The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.
Work on SQLite in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.