python - sqlite3.OperationalError : unable to open database file

标签 python database django sqlite django-settings

在 Django 中设置服务器时出现此错误。它是 sqlite3,这意味着它应该创建 .db 文件,但它似乎没有这样做。我已经将 SQLite 规定为后端,并规定了放置它的绝对文件路径,但没有运气。

这是一个错误还是我做错了什么? (只是在想,是不是在 Ubuntu 中指定的绝对文件路径不同?)

这是我的 settings.py 文件的开头:

# Django settings for OmniCloud project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': '~/Harold-Server/OmniCloud.db',                      # Or path to database file if using sqlite3.
    'USER': '',                      # Not used with sqlite3.
    'PASSWORD': '',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
}
}

最佳答案

Django NewbieMistakes

PROBLEM You're using SQLite3, your DATABASE_NAME is set to the database file's full path, the database file is writeable by Apache, but you still get the above error.

SOLUTION Make sure Apache can also write to the parent directory of the database. SQLite needs to be able to write to this directory.

Make sure each folder of your database file's full path does not start with number, eg. /www/4myweb/db (observed on Windows 2000).

If DATABASE_NAME is set to something like '/Users/yourname/Sites/mydjangoproject/db/db', make sure you've created the 'db' directory first.

Make sure your /tmp directory is world-writable (an unlikely cause as other thing on your system will also not work). ls /tmp -ald should produce drwxrwxrwt ....

Make sure the path to the database specified in settings.py is a full path.

Also make sure the file is present where you expect it to be.

关于python - sqlite3.OperationalError : unable to open database file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7670289/

相关文章:

python - 以数组格式返回该位置硬币所需的硬币数量

java - 游戏设计 - 玩家数据 - 我这样做对吗?

python - 使 django 只读字段在管理员上可见

python - 如何解释 scikit-learn 中的 roc_curve(Test,Predictions)

python - Django 1.8 RC1 : ProgrammingError when creating database tables

python - 使用 Python 的亚马逊社交网络

sql - 如何最好地处理缓慢变化的维度(SCD2)中的历史数据更改

java - 从数据库中删除项目 - Android Studio 中的 ListView

python - Django - 多对多模型不返回任何内容

python - Celery 从 Django 模块内部记录到文件