Sachi Murasaki
Sachi Murasaki

Reputation: 193

How to set up database for Django app on 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!

Upvotes: 16

Views: 12769

Answers (1)

Andrew Gorcester
Andrew Gorcester

Reputation: 19973

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.

Upvotes: 23

Related Questions