gpt4 book ai didi

python - sqlite3.OperationalError : unable to open database file

转载 作者:IT老高 更新时间:2023-10-28 21:33:58 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com