My migrations aren't showing up on Heroku, or I'm having other issues with my Django migrations.
Django best practices
When deploying Django apps to Heroku, it's best to stick to 12 Factor best practices. This can impact your database migrations in some specific ways.
Heroku applications are ephemeral, and this can be tricky if you're not familiar with the best practices around disposable apps.
For Django migrations, ephemeral means everything you want on your Heroku app needs to be checked into the Git repository or generated in the release phase.
Ensure that you have made your database migrations locally, and that they are checked into source control along with all other code:
# Local environment git checkout -b add-migrations python3 manage.py makemigrations python3 manage.py migrate git add -a git commit -m "Database migrations"
Then, add the following as the first line in your Procfile:
release: python manage.py migrate
Finally, deploy these changes to Heroku:
git add Procfile git commit -m "Add Release Phase to Procfile" git push heroku master
If you're still having issues:
- Ensure that your
/migrationsfolder is not in
/migrationsfolder should have a blank
python3 manage.py migratefails locally, it will fail on Heroku - so start by testing locally
- It's best to maintain dev/prod parity - so if it works locally but not on Heroku, try setting up a local Postgres database and testing your local migrations with a Postgres database.