ElasticBeanstalk Django: Please supply ENGINE value

Viewed 287

I am trying to install a Django app with ElasticBeanstalk. It's failing with the exception settings.DATABASES is improperly configured. Please supply the ENGINE value

Full error:

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.`

I am getting this error while one of my command is getting executed:

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

Here's my config/settings/production.py

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

I am kind of sure that EB is picking the config from this file only and not any other file because if I am changing something in this file, it is reflected while ElasticBeanstalk env creation. I have also searched in my whole application that DATABASES is mentioned only in either this file i.e. <app-rot>/config/settings/production.py or <app-root>/config/settings/local.py. At both the places, I have provided the ENGINE value as above.

Please let me know if I need to add any other relevant information

1 Answers

This took me forever to figure out (as most things with Django and EB). I think the environment variables you set in your console take preference over variables or settings you set anywhere else e.g. .ebextensions.

In my case the error was because my settings file was set correctly in my ebextensions but incorrectly in the console variables. Thanks @daniel for the hint

Related