Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
Your local db must be accessible from the Internet. If it's not, then you cannot use it on heroku. –  spirit walker Jul 22 '13 at 0:39

2 Answers 2

up vote 0 down vote accepted
  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.

share|improve this answer
    
Thanks! I've decided to just use the heroku postgres db and everything works. –  rocket_raccoon Aug 16 '13 at 15:10

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.