Django Migrations

Issue

My migrations aren't showing up on Heroku, or I'm having other issues with my Django migrations.

Resolution

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.

Steps

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

Troubleshooting

If you're still having issues:

  • Ensure that your /migrations folder is not in .gitignore or .slugignore.
  • Your /migrations folder should have a blank __init__.py file
  • If python3 manage.py migrate fails 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.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support
Terms of Service Privacy Cookies © 2019 Salesforce.com