sqlite3.operational错误:无法打开数据库fi

2024-04-28 19:28:38 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: 文件todjangodebug路径fordbsettings
3条回答

我也面临同样的问题。这是我的工作环境。

'ENGINE': 'django.db.backends.sqlite3', 
'NAME': '/home/path/to/your/db/data.sqlite3'

sqlite3的其他设置将相同/默认。
您需要创建data.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.

您没有指定绝对路径-您使用了一个快捷方式~,它可能在此上下文中不起作用。改用/home/yourusername/Harold-Server/OmniCloud.db

相关问题 更多 >