简体   繁体   English

Django 管理后端“操作错误”尝试编写只读数据库

[英]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.我在安装了 Django 1.6.1 的 Ubuntu 14.04 服务器上运行nginx I am attempting to use the default django admin backend for a project (usually at localhost/admin/).我正在尝试为项目使用默认的 django 管理后端(通常在 localhost/admin/)。

The issue I run into is OperationalError at /admin/ attempt to write a readonly database我遇到的问题是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) (当我更改 db.sqlite3 文件的 chmod 权限时更新,错误现在OperationalError at /admin/ unable to open database file读取OperationalError at /admin/ unable to open database file但我已经检查了Django 新手错误网站上的每个选项以获得答案并且没有骰子)

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 .一些答案谈到了生成的数据库文件db.sqlite3的 r+w+x 权限,据我所知,即使 db 文件上的777也没有做任何事情,所以我将它保持在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).据我所知,django 项目可以找到(所有页面都可以正常呈现,/admin 页面在没有 css 的情况下呈现。当我尝试使用 localhost/admin/ 登录并单击提交时,我得到了带有错误的 django 调试页面)。 They are all owned by root:root .它们都归root:root I have tried changing permissions for every file and directory to be owned by www-data:www-data but nothing.我曾尝试更改www-data:www-data拥有的每个文件和目录的权限,但什么也没有。

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')我什至尝试将 settings.py 更改为数据库的绝对路径而不是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...在所有的麻烦和 2 个多小时的撞墙之后,档案馆的答案......

I was using gunicorn, I took a cookie cutter set up from Digital Ocean which made the user django.我正在使用 gunicorn,我从 Digital Ocean 设置了一个饼干切割机,它使用户 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.原来在/etc/init/gunicorn.conf setuidsetgid被设置为用户 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 .如果您遇到此问题,请删除setuidsetgid或将它们设置为www-data

This error usually caused by running the server as a different user (i guess you are running a linux machine).这个错误通常是由以不同的用户身份运行服务器引起的(我猜你正在运行一台 linux 机器)。 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.如果您以 root/管理员身份创建项目并以较低状态的用户身份运行服务器,那么您将收到错误消息。

try running the server with sudo permission, ie尝试使用 sudo 权限运行服务器,即

sudo python3 manage.py runserver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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