使用django 1.6“settings.DATABASES未正确配置”

时间:2014-01-15 00:46:22

标签: python django postgresql

我在win7上使用pycharm 3和python / django在便携式环境中进行开发。我决定尝试将postgresql添加到我的virtualenv“R1”中的项目(“rob1”)中,并使用http://sourceforge.net/projects/pgsqlportable/

我将settings.py更改为包含:

DATABASES = {
'default': {
    'ENGINE':'django.db.backends.postgresql_psycopg2',
    'NAME': 'test',
    'USER': 'postgres',
    'PASSWORD': '123',
    'HOST': 'localhost',
    'PORT': '5432',
}
}

从民意调查教程(https://docs.djangoproject.com/en/dev/intro/tutorial01/)创建模型作为测试之后,我运行了syncdb并得到了:

Traceback (most recent call last):
  File "F:\PyCharm 3.0.1\helpers\pycharm\django_manage.py", line 23, in <module>
    run_module(manage_file, None, '__main__', True)
  File "f:\ppython275\App\Lib\runpy.py", line 176, in run_module
    fname, loader, pkg_name)
  File "f:\ppython275\App\Lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "f:\ppython275\App\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "F:\envs\r1\rob1\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "F:\envs\r1\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "F:\envs\r1\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "F:\envs\r1\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "F:\envs\r1\lib\site-packages\django\db\backends\__init__.py", line 157, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "F:\envs\r1\lib\site-packages\django\db\backends\dummy\base.py", line 15, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

运行manage.py diffsettings我得

ALLOWED_HOSTS = ['*']
BASE_DIR = 'F:\\envs\\r1\\rob1\\rob1'  ###
DATABASES = {'default': {'AUTOCOMMIT': True, 'ENGINE': 'django.db.backends.dummy', 'ATOMIC_REQUESTS': False, 'NAME': '', 'TEST_MIRROR': None, 'CONN_MAX_AGE': 0, 'TEST_NAME': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'PORT': '', 'HOST': '', 'USER': '', 'TEST_CHARSET': None, 'PASSWORD': '', 'OPTIONS': {}}}
DEBUG = True
INSTALLED_APPS = ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'getPost', 'gunicorn')
MIDDLEWARE_CLASSES = ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')
ROOT_URLCONF = 'rob1.urls'  ###
SECRET_KEY = '****'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SETTINGS_MODULE = 'rob1.settings'  ###
STATICFILES_DIRS = ('F:\\envs\\r1\\rob1\\rob1\\static',)
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
TEMPLATE_DEBUG = True
TIME_ZONE = 'UTC'
USE_L10N = True
USE_TZ = True
WSGI_APPLICATION = 'rob1.wsgi.application'    

Process finished with exit code 0

编辑:上面有更多错误信息,只有一个settings.py文件(在rob1中)

现在你开始我了。在设置.py中有一个额外的区域:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

有人可以告诉我如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

如果您使用的是dj_database_url.config(),则还需要设置DATABASE_URL

DATABASE_URL = "postgres://postgres:123@localhost:5432/test"
#                          ^user    ^pw ^host     ^port ^dbname