How to fix Django error: Attempt to write a readonly database ?

Published: September 26, 2022

Tags: Django; Protection Status

Got the following error "Attempt to write a readonly database" with a django web site after replacing the database.

Django app has been deployed on a digitalocean ubuntu droplet using Nginx and Gunicorn.

Change database ownership

Problem was that the django app has been deployed on a repertory owned by a user called for example 'johndoe':


however the database owner was "root"



-rw-rw-r-- 1 root     root     116928512 Sep 26 00:06 database_new.db
-rw-r--r-- 1 johndoe johndoe 116752384 Sep 26 02:07 database_old.db

to fix that just change database owner

sudo chown johndoe database.db

and the error was fixed.

Error origin

Error was due to the fact that I used root user to scp the new databse:

scp -rp database_new.db root@ip_address:/home/daidalos/johndoe/mysite/.

instead of

scp -rp database_new.db johndoe@ip_address:/home/johndoe/webapps/mysite/.