Created
March 21, 2022 08:28
-
-
Save camara90100/ba035d071033b1b32aa61f48ef598035 to your computer and use it in GitHub Desktop.
Remove (squash) Django Migrations without worrying about dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Remote db state must be at the same exact state of the local DB | |
| ### Steps will be done on two stages: | |
| ### 1. local db stage | |
| 1. make sure you are in your django project path, and run `find . -path "*migrations*" -name "*.py" -not -path "*__init__*" -exec rm {} \;` | |
| 2. pip install --upgrade --force-reinstall Django, because this path usually removes django's own migrations. | |
| 3. Remove django migrations history table from your local database. | |
| from django.db import connections | |
| with connections["default"].cursor() as cursor: | |
| cursor.execute("TRUNCATE django_migrations") | |
| 4. run make migrations | |
| 5. run migrate --fake | |
| 6. commit the new migrations files and the deleted migrations files, and don't be alarmed but the number of files deleted. | |
| ### 2. Server's db stage | |
| 1. if you have a managed server, like Elastic Beanstalk, disable the automated migrate command from your server config.. and don't allow it to run. | |
| 2. push your code. | |
| 3. run manage.py --fake manually on the server. | |
| 4. do a little dance or get a drink or something. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment