Attempt to write a readonly database - Django w/ SELinux error
You have to add writing rights to the directory in which your sqlite database is stored. So running chmod -R u+w /srv/mysite/
should help.
If a server is using custom user (e.g. www-data
) to access the database, the solution could be to change the owner of your database:
chown www-data:www-data /srv/mysite
chown www-data:www-data /srv/mysite/DATABASE.sqlite
In short, it happens when the application which writes to the sqlite database does not have write permission.
This can be solved in three ways:
- Granting ownership of
db.sqlite3
file and its parent directory (thereby write access also) to the user using chown (Eg:chown username db.sqlite3
) - Running the webserver (often gunicorn) as root user (run the command
sudo -i
before you rungunicorn
or djangorunserver
) - Allowing read and write access to all users by running command
chmod 777 db.sqlite3
(Dangerous option)
Never go for the third option unless you are running the webserver in a local machine or the data in the database is not at all important for you.
Second option is also not recommended. But you can go for it, if you are sure that your application is not vulnerable for code injection attack.