So I'm following the getting started guide from heroku with django. However when I run this command:
heroku run python manage.py syncdb
I get this error
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
I assumed this meant that the db wasn't set up yet... so I manually added the shared_db option as well:
heroku addons:add shared-database:5mb
But.. I still get the same error. What gives?
Project description This is a Django library for Heroku applications that ensures a seamless deployment and development experience.
EDITED:
As @mipadi has pointed out here (http://stackoverflow.com/questions/13001031/django-heroku-settings-injection/13092534), it can actually be as simple as this:
import dj_database_url
DATABASES = {'default' : dj_database_url.config() }
This works if you have a DATABASE_URL env variable set. heroku:pg_promote gets your there. Details below
Make sure you have Postgres on your Heroku
heroku addons:add heroku-postgresql:dev
Step 1: figure out your database url
heroku config | grep POSTGRESQL
The output will look something like this:
HEROKU_POSTGRESQL__URL: postgres://user:password@host:5432/blabla
Step 2: Grab the setting name from the previous step (e.g. HEROKU_POSTGRESQL_ROSE_URL) and put it in your settings file like so
DATABASES = {'default': dj_database_url.config(default=os.environ["HEROKU_POSTGRESQL_ROSE_URL"])}
[UPDATE] As Ted has pointed out, there's a way to promote the color URL to DATABASE_URL variable:
heroku pg:promote HEROKU_POSTGRESQL_ROSE_URL
Your database settings can then use DATABASE_URL as opposed to more exotic colored URLS
DATABASES = {'default': dj_database_url.config(default=os.environ["DATABASE_URL"])}
Bob is your uncle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With