1. Show migrations for an app $ python3 manage.py showmigrations orchestrator ... [X] 0051_auto_20191217_2328 [X] 0052_auto_20200212_2250 [X] 0053_job_miscellaneous 2. If you want to revert back the last 2 migrations $ python3 manage.py migrate orchestrator 0051_auto_20191217_2328 Operations to perform: Target specific migration: 0051_auto_20191217_2328, from orchestrator Running migrations: Rendering model states... DONE Unapplying orchestrator.0053_job_miscellaneous... OK Unapplying orchestrator.0052_auto_20200212_2250... OK 3. Show migrations again $ python3 manage.py showmigrations orchestrator ... [X] 0051_auto_20191217_2328 [ ] 0052_auto_20200212_2250 [ ] 0053_job_miscellaneous 4. Delete the undesired migration files $ rm 0052_auto_20200212_2250.py 0053_job_miscellaneous.py 5. Show migrations again $ python3 manage.py showmigrations orchestrator ... [X] 0051_auto_20191217_2328 6. Now make a new migration. This will have all latest changes in model $ python3 manage.py makemigrations Migrations for 'orchestrator': orchestrator/migrations/0052_job_miscellaneous.py - Add field miscellaneous to job 7. Now apply new migration $ python3 manage.py migrate Running migrations: Applying orchestrator.0052_job_miscellaneous... OK
3.20.2020
Revert back to previous Django Migration
This procedure is only for the development environment while actively working on changes. Say you have several migrations already created but since after making changes realized that some of them are unnecessary and you want to come up with just one migration before checking in code for production deploy. This procedure will revert back migrations to previous level and then will give opportunity to create just one migration file that can then be deployed to production. This can potentially damage databases if not applied properly so use your discernment.
Subscribe to:
Posts (Atom)