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.
-
If you still have the old code running on Heroku:
-
Back your database up
-
Reverse all of your migrations:
heroku run python manage.py migrate appname zero
-
Then deploy your new code:
git push heroku master
-
Then run the new migrations:
heroku run python manage.py migrate
-
-
If you’ve already deployed the new code to Heroku:
-
Back your database up
-
Manually delete your app’s tables from your database, as well as rows from the
django_migrations
table where theapp
matches your app name e.g. viaheroku pg:psql
(this may get tricky if you have other apps installed and inter-app dependencies) -
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.
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.