How to Fix failed Django  database migrations on Heroku --- Programming error

How to Fix failed Django database migrations on Heroku --- Programming error


2 min read


Heroku is a cloud application platform that provides deployment services for multiple technologies such as Django/python. It is essentially a Platform-as-a-Service (PaaS) cloud infrastructure, which simplifies hosting applications when compared to a cloud provider like AWS Elastic Compute Cloud(EC2) or others. Heroku makes deploying applications quite simple and for good reasons 🤓.

This platform equips us with a ready runtime environment and application servers. we benefit from seamless app integration with various development instruments, a pre-installed operating system, terminal, Dynos ( isolated virtualized Linux containers ), and redundant servers 🏢 .

Therefore, we don’t need to think about infrastructure management, unlike with AWS EC2. We only need to choose a subscription package and scale up when we need more resources.

We use AWS EC2 and Heroku (PaaS) to reach different goals, which is a subject worth reviewing.

A common error with Heroku deploys can be failed database migrations within your Heroku Dyno 😞.

which will be a case that when I run

heroku local web

the website works fine when I go to


or any other port that serves the app locally. However after I deploy the app to Heroku with git push heroku master, it returns


From personal experience, this issue might result from a change to a model and then deploying this change to your app's Heroku Dyno.

Assumptions. The app in question is still in development and as such our database tables aren't large and thus easily dispensable.

  • Reset the database in Heroku
  • Delete all the migrations files for the broken app locally except the file.

  • Runpython3 makemigrations and python3 migrate. This will repopulate the migrations folder with clean migration files.

  • Push changes to the default branch and ensure that you do not have the migrations directories in .gitignore files.

  • Deploy changes to Heroku

  • Run the Heroku shell with the command heroku run bash
  • Run python3 migrate

That should fix the error.

Thanks for the audience 🤗, I hope this fix saves you a lot of debugging time 😃 . feel free to drop a like, comment, and share 😉.