Django是“无法打开数据库文件” [英] Django is "unable to open database file"

查看:120
本文介绍了Django是“无法打开数据库文件”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行python manage.py syncdb后,我收到一个错误,说无法打开数据库文件。

after running "python manage.py syncdb" i gett an error saying "unable to open database file".

这里是我的settings.py的重要部分:

here is the important part from my 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的权限:

and here are the permissions for "apps.db":

-rw-r--r-- 1 root root 33792 19. Jul 10:51 apps.db

我的django服务器是从apache调用...我不知道它是否与权限有关,但将apps.db的所有者更改为www -data未能工作

My django server is called from apache... i don't know if it has to do with the permissions but changing the owner of apps.db to "www-data" did not work either

以确保www-我做了以下:

to ensure www-data can access all of this i did the following:

执行了以下操作:

chown -R www-data apps
rm apps.db
su www-data
python manage.py syncdb

但仍然无效:(

推荐答案

我通过更改DATABASE_NAME到绝对路径: /var/www/apps/apps.db

I solved the error by changing the DATABASE_NAME to an absolute path: /var/www/apps/apps.db.

在Windows机器上,反斜杠应转义为: C:\\path\\to\\database\\database_name.db

On a windows machine, backslash should be escaped like: C:\\path\\to\\database\\database_name.db.

这篇关于Django是“无法打开数据库文件”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆