sqlite3.OperationalError:无法打开数据库文件

问题描述:

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

I get this error when setting up a server in Django. It is sqlite3 which means it should create the .db file but it doesn't seem to be doing so. I've stipulated SQLite as the backend and an absolute file path for where to put it, but no luck.

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

Is this a bug or am I doing something incorrect? (Was just thinking, is the absolute file path specified differently in Ubuntu?)

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

Here is the beginning of my settings.py file:

# 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.
}
}


a href =https://code.djangoproject.com/wiki/NewbieMistakes#DjangosaysUnabletoOpenDatabaseFilewhenusingSQLite3 =noreferrer> Django NewbieMistakes

Django NewbieMistakes


PROBLEM您正在使用SQLite3,您的DATABASE_NAME设置为
数据库文件的完整路径,数据库文件可由Apache写入
,但您仍会收到以上错误。

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.

解决方案确保Apache也可以写入
数据库的父目录。 SQLite需要能够写入此目录。

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

确保数据库文件的完整路径的每个文件夹不会以数字启动
,例如。 / www / 4myweb / db(在Windows 2000上观察)。

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

如果DATABASE_NAME设置为
'/ Users / yourname / Sites / mydjangoproject / db / db',确保你
先创建了'db'目录。

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

确保你的/ tmp目录是世界可写的作为
其他的东西在你的系统上也不行)。 ls / tmp -ald应该
产生drwxrwxrwt ....

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 ....

确保settings.py中指定的数据库的路径是完整的
路径。

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.