settings.DATABASES配置不正确

时间:2013-08-19 20:50:17

标签: 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.

所以我无法弄清楚为什么说它配置不当?

1 个答案:

答案 0 :(得分:1)

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

  

包含要使用的所有数据库的设置的字典   Django的。它是一个嵌套字典,其内容映射数据库别名   到包含单个数据库选项的字典。

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