简体   繁体   中英

Django admin backend 'Operational Error' attempt to write a readonly database

This question seems to have been asked many times but all the solutions I have checked haven't yet worked for me. I am running nginx on a Ubuntu 14.04 server with Django 1.6.1 installed. I am attempting to use the default django admin backend for a project (usually at localhost/admin/).

The issue I run into is OperationalError at /admin/ attempt to write a readonly database

(Update when I changed chmod permissions for the db.sqlite3 file the error now reads OperationalError at /admin/ unable to open database file but I have checked every option on the Django Newbie Mistakes website for the answer and no dice)

Some answers talked about the r+w+x permissions for the generated database file db.sqlite3 as far as I can tell even 777 on the db file doesn't do anything so I've kept it at 656 .

As far as I can tell the django project works find (all pages render fine, the /admin page renders without css. When i attempt to login using localhost/admin/ and click submit I get the django debug page with the error). They are all owned by root:root . I have tried changing permissions for every file and directory to be owned by www-data:www-data but nothing.

I have even tried changing the settings.py to have an absolute path to the db instead of os.path.join(BASE_DIR, 'db.sqlite3')

I think its down to an ownership problem but I'll take any help.

After all that hassle and 2+ hours of banging my head against a wall, the answer for the archives...

I was using gunicorn, I took a cookie cutter set up from Digital Ocean which made the user django. I thought it the cookie cutter approach would be a shortcut which was easy to modify and skipped the boring bits. It turns out in /etc/init/gunicorn.conf setuid and setgid was set to the user django. My fault for not reading the documentation and assuming these meant little.

If you are having this problem either delete setuid or setgid or set them to www-data .

This error usually caused by running the server as a different user (i guess you are running a linux machine). If you have created the project as a root/administrator and running the server as a user with lower status, then you will get the error.

try running the server with sudo permission, ie

sudo python3 manage.py runserver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM