当我运行时,python manage.py runserver
我收到以下错误:
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1cc9cd0>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/South-0.7.6-py2.7.egg/south/models.py", line 2, in <module>
from south.db import DEFAULT_DB_ALIAS
File "/usr/local/lib/python2.7/dist-packages/South-0.7.6-py2.7.egg/south/db/__init__.py", line 81, in <module>
db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
这是我的settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'foureggs',
'USER': 'myuser',
'PASSWORD': 'mypass',
'HOST': '',
'PORT': '',
}
}
这是一个具有相同问题的问题。答案说“您的设置中应该有一个名为'default'的数据库”。我并没有真正遵循这一点。我的数据库名称是“foureggs”,所以显然我想使用它。
更新:当我这样做时,python manage.py diffsettings
我得到以下输出,看起来不正确(仅粘贴相关的 DATABASE 行,其余设置看起来不错):
DATABASES = {'default': {'ENGINE': 'django.db.backends.dummy', 'TEST_MIRROR': None, 'NAME': '', 'TEST_CHARSET': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'PORT': '', 'HOST': '', 'USER': '', 'TEST_NAME': None, 'PASSWORD': '', 'OPTIONS': {}}}
我的项目中只有一个设置文件,它位于 app 目录中,这是正确的。上面的 DATABASE 行从何而来?
更新2:我想出了问题所在。这是我按照Heroku 部署指南settings.py
的指示添加的这两行。当我将它们注释掉时,一切正常。现在我需要弄清楚为什么它会导致问题。
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()