【问题标题】:settings.DATABASES is improperly configuredsettings.DATABASES 配置不正确
【发布时间】:2013-08-19 20:50:16
【问题描述】:

这里是新手,抱歉

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

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

【问题讨论】:

    标签: django postgresql psycopg2


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-12-10
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      相关资源
      最近更新 更多