Sologoub
Sologoub

Reputation: 5352

How to configure Django to use Heroku Dev Postgre while local?

I'm trying to configure local dev environment with Heroku, Django and virtualenv. Everything seems to be working when pushed to Heroku hosting, but locally, I cannot seem to connect to the Heroku-supplied dev Postgre DB.

According to the instructions, I added the following to settings.py:

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

But this doesn't seem to get invoked while running locally. Get the following exception:

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Is it even possible to connect to the Heroku hosted dev Postgre from a local instance of Django? If it is, what am I missing?

Thank you!

Upvotes: 3

Views: 1279

Answers (1)

Sologoub
Sologoub

Reputation: 5352

This turned out to be relatively straightforward...

dj_database_url.cofig() takes a parameter default. Database info on heroku can be found here: https://postgres.heroku.com/databases/

If your db info and credentials are as follows: Host somehost.amazonaws.com Database somedb User foo Port 5432 Password bar

Then the settings.py entry should look like this:

import dj_database_url
DATABASES['default'] =  dj_database_url.config(default='postgres://foo:[email protected]:5432/somedb')

Same steps work if you are using a local Postgre setup as well.

Upvotes: 3

Related Questions