1

I am unsuccesfully getting my django app deployed on heroku to use my local postgres db.

My DATABASE settings are as follows:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'foo',
        'PASSWORD': 'bar',
        'HOST': 'localhost',
        'PORT': '',
    }
}

Everything runs fine locally. Following the instructions from https://devcenter.heroku.com/articles/django, I add the following bit a code to the bottom of my settings file:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://foo:bar@localhost/mydb')}
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

However, this produces the following error:

OperationalError at / could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

My django app runs fine on Heroku, except when it needs to connect to the database, which is where it throws this error.

Anyone know what I am doing wrong here?

1
  • Your local db must be accessible from the Internet. If it's not, then you cannot use it on heroku. Commented Jul 22, 2013 at 0:39

2 Answers 2

1

Simply put, your current configuration defines the database host as localhost while you should be pointing it at your hosts public IP (or fully qualified domain name).

But this seems like an anti-pattern. You really should be using Heroku's development databases for this stuff, and if you have any local data you'd like to import there, just make a database dump and load it.

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Allow remote postgres access to your local db. example
  2. Change the settings file to something like this:

DATABASES = {

  'default': {
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'NAME': 'your db name',
      'USER': 'your username',
      'PASSWORD': 'password',
      'HOST': 'Your computer's IP',
      'PORT': '6122',
  }

Or you have to clone your local db to heroku postgres and change your settings to use that db.

1 Comment

Thanks! I've decided to just use the heroku postgres db and everything works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.