我正在使用https://devcenter.heroku.com/articles/django教程在Heroku上设置Django应用程序,我遇到了运行heroku run python manage.py syncdb
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
我在本地同步时遇到同样的错误。我已经阅读了StackOverflow上的所有线程,但没有解决这个问题。 settings.py的相关部分:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
import dj_database_url
DATABASES['default'] = dj_database_url.config()
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
答案 0 :(得分:9)
我不确定为什么教程会掩盖这一点 - 我已经看到类似的问题经常出现 - 但这是我采取的解决问题的步骤。值得阅读Postgres文档 - https://devcenter.heroku.com/articles/heroku-postgresql
1)使用终端
中的heroku addons | grep POSTGRES
创建Postgres数据库
2)将数据库连接到应用程序 - heroku addons:add heroku-postgresql:dev
3)推广数据库URL的URL:heroku pg:promote HEROKU_POSTGRESQL_RED_URL
4)将其添加到settings.py中:
DATABASES['default'] = dj_database_url.config(default=os.environ.get('DATABASE_URL'))
答案 1 :(得分:-1)
在您的设置中输入:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Or another database
'NAME': 'database.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}