Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up database for Django app on Heroku?

Tags:

django

heroku

I'm a complete Heroku noob and I'm trying to set up a Django app on Heroku. I can't figure out what to enter for these settings in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

Can anybody help me out? Thank you!

like image 676
Sachi Murasaki Avatar asked Jun 01 '13 02:06

Sachi Murasaki


1 Answers

You can do it manually by looking at your database info in the dashboard or by running "heroku config" to see the DB configuration string. But the best way by far is as detailed in the Heroku Getting Started guide for Django. Add dj-database-url==0.2.1 to your requirements.txt file and then:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

in lieu of other database definitions.

like image 170
Andrew Gorcester Avatar answered Sep 20 '22 19:09

Andrew Gorcester