django - settings.DATABASES 配置不当

标签 django postgresql psycopg2

这里是新手,抱歉

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

相关文章:

django - 如何在 Django 项目上访问 SQLite 的 db shell?

python - Django 向数据库表中的所有用户发送电子邮件

macos - 来自 Mac 的 Postgresql 连接问题

python - 从数据库中的表中获取数据

django - 错误 : could not determine PostgreSQL version from '10.3' - Django on Heroku

django - 隐藏 Django Rest Framework 路由器 Api 查看页面

python - 如何在 Django ORM 中获得最大值

sql - 哪个查询效率更高?内部联接与子查询?总计与有

ruby-on-rails - 关于运行 rake db :seed task 的问题

python - PostgreSQL:无法删除名为 "user"的特定表