0

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!

2
  • 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. Commented Jul 22, 2014 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! Commented Jul 23, 2014 at 6:54

2 Answers 2

1

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.

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

Comments

0

I had the same problem. Commenting local_settings content solved it.

Comments

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.