Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm trying to migrate my postgres database to Heroku for a django application. In my settings.py file, I have the following, as dictated by the Heroku tutorial:

import dj_database_url
DATABASES = {'default': dj_database_url.config()}

However, when I run heroku run python manage.py syncdbI get the following error:

django.db.utils.OperationalError: 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?

What am I missing? Thanks in advance!

share|improve this question
1  
If we're reading the same tutorial, it suggests using DATABASES['default'] = dj_database_url.config(). You've completely replaced the DATABASES dictionary; they've simply added a new key. That might not be the issue, but it's worth checking. Also, make sure you've git committed and git pushed your latest code to Heroku. – Alex P Jul 22 '14 at 9:38
    
Hey Alex, thanks for your help. Turns out, however, that I had another file in my settings directory that was messing things up. Commenting that out made everything work! – user3858526 Jul 23 '14 at 6:54

So it turns out the that the problem was that I had another file called local.py in my settings folder for my project. Tree as follows:

├── microblog
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings
│   │   ├── base.py
│   │   ├── base.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── local.py
│   │   └── local.pyc
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── Procfile
└── requirements.txt

Since I was following the Getting Started wit Django Tutorial, I had the following in my local.py file:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'USER': '<user>',
        'PASSWORD': '<pwd>',
        'NAME': '<name>',
        'HOST': 'localhost',
    }
}

That was causing the problem. I tried adding the file to my .gitignore, but that didn't work. The solution was to actually comment these lines out.

share|improve this answer

I had the same problem. Commenting local_settings content solved 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.