Django是“无法打开数据库文件”。

运行“python manage.py syncdb”后,我得到一个错误,说“无法打开数据库文件”。 这是我的settings.py的重要部分:
DATABASE_ENGINE = 'sqlite3'    # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'apps.db'      # Or path to database file if using sqlite3.
DATABASE_USER = ''             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
这是“apps.db”的权限:
-rw-r--r-- 1 root root 33792 19. Jul 10:51 apps.db
我的django服务器是从apache调用的......我不知道它是否与权限有关,但是将apps.db的所有者更改为“www-data”也不起作用 [编辑] 为了确保www-data可以访问所有这些我做了以下事情: 做了以下事情:
chown -R www-data apps
rm apps.db
su www-data
python manage.py syncdb
但它仍然无法正常工作:(     
已邀请:
来自NewbieMistakes的解决方案   确保Apache也可以写入的父目录   数据库。 SQLite需要能够写入此目录。      确保数据库文件的完整路径的每个文件夹都不会启动   与数字,例如。 / www / 4myweb / db(在Windows 2000上观察)。      如果DATABASE_NAME设置为类似的内容   '/ Users / yourname / Sites / mydjangoproject / db / db',确保你有   首先创建了'db'目录。      确保你的/ tmp目录是世界可写的(不太可能是因为   你系统上的其他东西也行不通)。 ls / tmp -ald应该   生产drwxrwxrwt ....      确保settings.py中指定的数据库路径是完整的   路径。     
我通过将DATABASE_NAME更改为绝对路径来解决错误:
/var/www/apps/apps.db
。 在Windows机器上,反斜杠应该像以下一样进行转义:
C:\path\to\database\database_name.db
。     
DATABASE_NAME已弃用。您必须使用当前支持的格式。 即
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': 'C:/ispdb.sqlite',
    'USER': '',
    'PASSWORD': '',
    'HOST': '',
    'PORT': ''

}
另请参阅django网站弃用的其他设置。:))     
对于我的linux系统,我必须向db.sqlite3和包含它的目录授予进程所有者写权限!你可以改为setfacl!例如:(https://serverfault.com/questions/484818/best-way-to-set-up-permissions-with-nginx-php-fpm-on-shared-hosting)。 (py2.7)[me @ server django-project-container] $ ls -la djangoproject /
drwxrwxr-x. 6 root nginx  4096 Jun 14 01:05 .
drwxr-xr-x. 6 root root  4096 Jun 13 23:47 ..
-rwxrwxrwx. 1 root nginx 49152 Jun 14 01:05 db.sqlite3
    
好吧,我在这个问题上回答了这个问题。 http://goo.gl/KAuXz 我遇到了完全相同的问题。这是我的设置工作。
'ENGINE': 'django.db.backends.sqlite3', 
'NAME': '/home/neo/django/db/data.sqlite3'
sqlite3的其他设置将是相同/默认的。     
要更改父目录的权限,可以使用以下命令集: 检查apache v2的apache进程:
ps -ef | grep apache | grep -v grep
用户/组是www-data
chgrp www-data /path/to/mydir
chmod g+w /path/to/mydir
参考:https://askubuntu.com/questions/58725/how-do-we-know-that-a-directory-is-apache-writable     

要回复问题请先登录注册