gpt4 book ai didi

django - settings.DATABASES 配置不当

转载 作者:行者123 更新时间:2023-11-29 13:33:36 27 4
gpt4 key购买 nike

这里是新手,抱歉

  • Mac OSX 10.8 Python 2.7(安装自制软件)
    • PostgreSQL 9.4(安装自制软件)
    • psycopg2 2.5(与 macports 一起安装)
    • Django 1.0.4(通过 python setup.py install 安装)

我正在使用 this tutorial ,在启动 python manage.py shell 之后,我运行了

>>> from django.db import connection
>>> cursor = connection.cursor()

得到以下内容:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

我的 settings.py 文件的 DATABASES 部分如下所示:

DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2'  #postgresql_psycopg2           
DATABASE_NAME = 'mydatabase' #mydatabase
DATABASE_USER = 'sarahr6' # 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.

所以我不明白为什么它说配置不正确?

最佳答案

您需要指定 DATABASES settings.py 中的字典:

A dictionary containing the settings for all databases to be used with Django. It is a nested dictionary whose contents maps database aliases to a dictionary containing the options for an individual database.

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydatabase',
'USER': 'sarahr6',
'PASSWORD': '',
'HOST': '',
'PORT': ''
}
}

关于django - settings.DATABASES 配置不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18322861/

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