[Django]-ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details

2👍

Did you try the stuff in the documentation at https://devcenter.heroku.com/articles/django#django-settings?

import dj_database_url
DATABASES['default'] =  dj_database_url.config()

It says

Django settings

Next, configure the application for the Heroku environment, including
Heroku’s Postgres database. The dj-database-url module will parse the
values of the DATABASE_URL environment variable and convert them to
something Django can understand.

Make sure ‘dj-database-url’ is in your requirements file, then add the
following to the bottom of your settings.py file:

settings.py

# Parse database configuration from $DATABASE_URL
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'),
)
👤sultan

6👍

Both Sultan and Joe are correct, and if you put them together and dig a little it works, I just want to lay it out a little clearer with an addition that helped me. These instructions on the Heroku site explain how to set it up including what Sultan mentioned, adding this section to settings.py:

# Parse database configuration from $DATABASE_URL
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'),
)

Then, (and what those instructions don’t mention) in your Heroku account go to your Databases section and select the database you would like to use. Go to ‘Connection Settings’ (two little arrows going opposite directions) and select the Django option. That code should look like what Joe mentioned:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', 
        'NAME': 'your_db_name',
        'HOST': 'your_host',
        'PORT': '5432',                    
        'USER': 'your_db_user_name',
        'PASSWORD': 'your_password',                             
    }
}

Paste this at the bottom of your settings.py file and sync your DB.

2👍

Your are defining the DATABASES = {'default': {... }} twice.

Solution:

If you are using heroku to serve your database then use this

import dj_database_url

DATABASES['default'] =  dj_database_url.config()

if you’re trying to connect to an external database server comment the two lines above and use this

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

1👍

Why don’t you try this:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2', 
    'NAME': 'yourdatabasename',
    'HOST': 'localhost',
    'PORT': '',                    
    'USER': 'yourusername',
    'PASSWORD': 'yourpassword',
    }
}

and after that apply this:

db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

0👍

You haven’t defined any of the database info.
Your DATABASES section should look something like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', 
        'NAME': 'your_db_name',                     
        'USER': 'your_db_user_name',
        'PASSWORD': 'your_password',
        'HOST': 'ec2-23-21-133-106.compute-1.amazonaws.com', # Or something like this
        'PORT': '5432',                     
    }
}

Leave a comment