python - ElasticBeanstalk Django : Please supply ENGINE value

标签 python django postgresql amazon-elastic-beanstalk

我正在尝试使用 ElasticBeanstalk 安装 Django 应用程序。它失败了,异常是 settings.DATABASES is improperly configured. Please supply the ENGINE value

完整错误:

Command failed on instance. Return code: 1 Output: (TRUNCATED)... 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. 
container_command 01_migrate in .ebextensions/15_my.config failed. For more 
detail, check /var/log/eb-activity.log using console or EB CLI.`

我在执行其中一个命令时遇到此错误:

01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
leader_only: True

这是我的 config/settings/production.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'ebdb',
    'USER': 'djangousername',
    'PASSWORD': 'djangopassword',
    'HOST': env('RDS_HOSTNAME'),
    'PORT': '5432'
}
}

我有点确定 EB 仅从该文件而不是任何其他文件中选择配置,因为如果我更改该文件中的某些内容,它会在 ElasticBeanstalk env 创建时反射(reflect)出来。我还在我的整个应用程序中搜索了 DATABASES仅在该文件中提及,即 <app-rot>/config/settings/production.py<app-root>/config/settings/local.py .在这两个地方,我都提供了 ENGINE值同上。

如果我需要添加任何其他相关信息,请告诉我

最佳答案

这让我花了很长时间才弄清楚(就像 Django 和 EB 的大多数事情一样)。我认为您在控制台中设置的环境变量优先于您在其他任何地方设置的变量或设置,例如.ebextensions.

在我的例子中,错误是因为我的设置文件在我的 ebextensions 中设置正确,但在控制台变量中设置不正确。感谢@daniel 的提示

关于python - ElasticBeanstalk Django : Please supply ENGINE value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44090071/

相关文章:

Django 复杂注释

postgresql - 如何查询 JSON 元素

sql - 如何在 PostgreSQL 中存储和查询同一文档的版本?

python - 在 request.POST 中处理来自多个表单的数据

Django 窗体 FileField 错误 'This Field is required'

Python:MySQLdb 在 Linux 上运行良好,而不是在 Windows 上

django - 获取 Django POST 请求的 API

database - 使用 pgAdmin III 客户端连接到 Heroku DB 时出现问题

python - 使用 "with open() as file"方法,如何多次写入?

Python 将 float 写入 Postgresql,但精度较低