[Django]-Is it possible to reset django migrations on an application deployed on heroku?

3👍

Pushing to Heroku is part of the solution, but not all of it. This updates the migration files, but not the django_migrations table in your database.

  1. If you still have the old code running on Heroku:

    1. Back your database up

    2. Reverse all of your migrations:

      heroku run python manage.py migrate appname zero
      
    3. Then deploy your new code:

      git push heroku master
      
    4. Then run the new migrations:

      heroku run python manage.py migrate
      
  2. If you’ve already deployed the new code to Heroku:

    1. Back your database up

    2. Manually delete your app’s tables from your database, as well as rows from the django_migrations table where the app matches your app name e.g. via heroku pg:psql (this may get tricky if you have other apps installed and inter-app dependencies)

    3. Run your new migrations:

      heroku run python migrate
      

Another, probably safer, option if you’ve already deployed the new code is to rollback to a version that reflects your database schema, then use option 1 above. In this case you can rollback again to the new version instead of doing a regular release.

👤Chris

1👍

Yes it can be done by two ways.

  • You can generate fixture for your current database schema if no such column is deleted or altered.
  • You can dump your database than just remove database from your db server and migrate again! Than load dumped data into fresh db, this will keep your previous data safe.

Leave a comment