Python 配置不正确:设置。数据库配置不正确。请提供发动机值
我正在heroku上建立我的django项目。我一直在遵循文档,但是当我Python 配置不正确:设置。数据库配置不正确。请提供发动机值,python,django,heroku,django-postgresql,Python,Django,Heroku,Django Postgresql,我正在heroku上建立我的django项目。我一直在遵循文档,但是当我领班开始时我收到一个错误,我不能完全弄清楚。我已经设置了我的引擎文件,但它似乎不想工作 完全回溯: Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/nir/nirla/venv/lib/python2.
领班开始时
我收到一个错误,我不能完全弄清楚。我已经设置了我的引擎文件,但它似乎不想工作
完全回溯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Users/nir/nirla/venv/lib/python2.7/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.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'yourdatabasename',
'HOST': 'localhost',
'PORT': '',
'USER': 'yourusername',
'PASSWORD': 'yourpassword',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
我似乎不明白这是什么意思,但表面上看不太对
以下是我的设置.py的一部分,我认为可能与此问题有关:
import os
import dj_database_url
ON_HEROKU = os.environ.get('ON_HEROKU')
HEROKU_SERVER = os.environ.get('HEROKU_SERVER')
if ON_HEROKU:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgresql',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '',
}
}
DATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
STATIC_URL = '/static/'
# only refers to the location where your static files should end up after running manage.py collectstatic. you shouldn't really need collectstatic) when developing locally
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../static'),
)
一个能准确解释什么是错的以及发生了什么的答案将非常有帮助。提前谢谢 您正在使用设置数据库['default']
。无论在这条线之前发生了什么:
DATABASES['default'] = dj_database_url.config()
当您完全替换数据库配置时,它是没有意义的。dj_database_url.config()
从database_url
环境变量加载数据库配置,如果未设置该变量,则返回{}
根据错误判断,您根本没有设置数据库\u URL
。根据dj\u database\u url.config()
行前面的代码判断,您根本不应该使用dj\u database\u url.config()
函数
如果确实要使用它,请至少构建一个默认URL:
if ON_HEROKU:
DATABASE_URL = 'postgresql://<postgresql>'
else:
DATABASE_URL = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = {'default': dj_database_url.config(default=DATABASE_URL)}
如果在\u HEROKU上:
数据库URL='postgresql://'
其他:
DATABASE_URL='sqlite://'+os.path.join(BASE_DIR'db.sqlite3')
DATABASES={'default':dj_database_url.config(default=database_url)}
您可以对本地主机使用以下设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DatabaseName',
'USER': 'DatabaseUserName',
'PASSWORD': 'DatabaseUserpassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
我在运行命令时使用django租户用户时遇到了相同的问题: python manage.py设置\u dtu\u租户
这是因为我的项目文件夹中有一个名为“settings”的文件夹,其级别与我的settings.py相同。删除此文件夹后,问题就消失了。为什么不试试这个:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Users/nir/nirla/venv/lib/python2.7/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.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'yourdatabasename',
'HOST': 'localhost',
'PORT': '',
'USER': 'yourusername',
'PASSWORD': 'yourpassword',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
然后应用此命令:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/Users/nir/nirla/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Users/nir/nirla/venv/lib/python2.7/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.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'yourdatabasename',
'HOST': 'localhost',
'PORT': '',
'USER': 'yourusername',
'PASSWORD': 'yourpassword',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
您的答案似乎与@ApathyBear共享的代码中显示的错误消息不匹配。请把问题再读一遍。