In the process of developing a project on Django, we may encounter an unpleasant situation when some packages and modules were removed and, accordingly, models from these packages were no longer used. But at the same time, squash of application migrations does not allow removing these packages, since migrations have many circular dependencies. As a result, removing unnecessary packages becomes a rather difficult task. Since resolving such dependencies becomes a non-trivial task. For me, such an unpleasant package was Django CKEditor, which was present almost everywhere. As a result, this package due to migrations remained for quite a long time in the list of requirements.txt, although in fact it was not used on the site at all.
In order to get rid of such dependencies of migrations, you need to delete all migrations, while not removing the content that was created by these migrations. And then create a new initial migration and apply it to the database also without making new changes to the database structure.
How to do it?
Return all migrations to zero state with the fake parameter. This means that the migration information will be deleted, but the content will not change.
python manage.py migrate app zero --fake
Delete migration files from repository
git rm "app/migrations/*"
Create a new migration file
python manage.py makemigrations app
Start a new migration with the fake parameter to add information about the migration to the database, but not to change the database structure.
python manage.py migrate app --fake
Carefully apply this approach to adjusting migrations and better create a new migration on the test server to make sure that you do everything correctly and the database will not broken.
At the same time, on the test server you can create a new migration and add it to the git repository..
Then on the production server you will need to do the following.
python manage.py migrate app zero --fake git pull python manage.py migrate app --fake
For Django, I recommend Timeweb VDS-server .