python - 带 Django 1.6的"settings.DATABASES is improperly configured"

  显示原文与译文双语对照的内容

我正在使用 pycharm 3开发一个带有 python/Django的可移植环境。 在我的项目("rob1") 中,我决定尝试添加 postgresql,这是 inside的virtualenv"r1",并且我使用 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',
}
}

在 polls ( https://docs.djangoproject.com/en/dev/intro/tutorial01/ ) as作为测试创建模型之后,我运行syncdb并得到:


Traceback (most recent call last):
 File"F:PyCharm 3.0.1helperspycharmdjango_manage.py", line 23, in <module>
 run_module(manage_file, None, '__main__', True)
 File"f:ppython275AppLibrunpy.py", line 176, in run_module
 fname, loader, pkg_name)
 File"f:ppython275AppLibrunpy.py", line 82, in _run_module_code
 mod_name, mod_fname, mod_loader, pkg_name)
 File"f:ppython275AppLibrunpy.py", line 72, in _run_code
 exec code in run_globals
 File"F:envsr1rob1manage.py", line 10, in <module>
 execute_from_command_line(sys.argv)
 File"F:envsr1libsite-packagesdjangocoremanagement__init__.py", line 399, in execute_from_command_line
 utility.execute()
 File"F:envsr1libsite-packagesdjangocoremanagement__init__.py", line 392, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
 File"F:envsr1libsite-packagesdjangocoremanagementbase.py", line 242, in run_from_argv
 self.execute(*args, **options.__dict__)
 File"F:envsr1libsite-packagesdjangocoremanagementbase.py", line 285, in execute
 output = self.handle(*args, **options)
 File"F:envsr1libsite-packagesdjangocoremanagementbase.py", line 415, in handle
 return self.handle_noargs(**options)
 File"F:envsr1libsite-packagesdjangocoremanagementcommandssyncdb.py", line 57, in handle_noargs
 cursor = connection.cursor()
 File"F:envsr1libsite-packagesdjangodbbackends__init__.py", line 157, in cursor
 cursor = self.make_debug_cursor(self._cursor())
 File"F:envsr1libsite-packagesdjangodbbackendsdummybase.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:envsr1rob1rob1' ###
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:envsr1rob1rob1static',)
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中)

现在你开始查看 settings 。py中的其他区域:


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

谁能告诉我怎么修复这个问题?

时间: 作者:

如果使用 dj_database_url.config(),还需要设置 DATABASE_URL:


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

作者:
...