2

I am trying to get my first django app up, but I'm running into this db error:

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

This happens whenever I try to syncdb, migrate, or createsuperuser

I am configuring my DATABASES variable like:

DATABASES = {'default' : dj_database_url.config(default=os.environ["HEROKU_POSTGRESQL_OLIVE_URL"]) }

Is there something else I need to configure or am doing wrong?

EDIT (SOLVED):

Thanks for helping me narrow down the problem, I've found the solution.

Since this was the first time I deployed to heroku and the first time I used the two scoops django directory format. I thought doing something like

python manage.py syncdb # would be okay

instead beause my settings folder looks like

.../settings
    base.py
    local.py
    production.py
    demo.py
    # ...

I need to do

python manage.py syncdb --app.settings.demo
1
  • Are you sure "HEROKU_POSTGRESQL_OLIVE_URL" is defined? Heroku has several database options. Commented Mar 27, 2015 at 14:47

2 Answers 2

1

Your syntax seems right, try using DATABASE_URL after verifying you promoted HEROKU_POSTGRESQL_OLIVE_URL, although it should work even when not promoted.

$ heroku pg:promote HEROKU_POSTGRESQL_OLIVE_URL

and then:

import dj_database_url

DATABASES = {
    'default': dj_database_url.config(default=os.getenv('DATABASE_URL'))
}

This setup should be working. Else, check that you are working on the right settings file. You can verify this by running:

$ heroku run python manage.py shell

and then:

>>> from django.conf import settings
>>> print settings.DATABASES['default']

and verify result.

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

Comments

0

I had an error in .gitignore and my local settings were getting set by Heroku by mistake.

This will also cause this error message message.

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.