I've added a Postgres database to my Heroku app, and am trying to connect my Django app to it. However, my app always connects to the local Postgres database instead.
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'app_db',
'USER': 'admin',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
}
}
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
I've set 'DATABASE_URL' in the .env file to be the url for the Postgres database on my Heroku app, but it doesn't seem to update the database. How do I force my app to connect to the Heroku database rather than the local one?
DATABASE_URLenvironment variable with something likeimport os; print os.environ['DATABASE_URL']? Just put this beforedb_from_envvariable, restart the server and check output.https://github.com/theskumar/python-dotenvmaybe.dj_database_url.config()doesn't read a file, instead it checks the environment variable value