Deploying Django to Heroku: Connecting Heroku Postgres

Bennett Garner
7 min readJan 25, 2019

Here’s everything you need to know to get your database working on Heroku.

Deploying a Django app successfully to Heroku is far from self-explanatory.

In a different post, I outlined how to get barebones Django running as a brand new Heroku app.

But Django isn’t very useful unless it has a database to talk to, and Heroku doesn’t work with Django’s default SQLite database.

Luckily, Heroku Postgres databases are free or cheap for hobby developers. In this guide, I’ll show you how to set it up.

(Are you an experienced dev just looking for some source code? Happy to oblige.)

Local vs. Remote

Let me make it clear what we’re doing here.

We have a Django app that works locally on our computer. If we run:

python manage.py runserver

Then, we’ll see a working Django app at http://localhost:8000

That local version of the Django app is using db.sqlite3 as its database.

However, when we visit the Heroku version, YourProjectName.herokuapp.com, Heroku will need to use a Postgres database instead.

--

--

Bennett Garner
Bennett Garner

Written by Bennett Garner

DeveloperPurpose.com — Build a coding career with meaning and purpose 💻 Top writer in technology ✍️

Responses (18)