Django admin backend 'Operational Error' a

2019-03-01 22:38发布

问题:

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.

回答1:

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.