A long time ago in a galaxy far far away I started a nice clean greenfield projects. Alas, it is 6 years later, and the fields, once green, are now brown. My project now has 459 project-level migrations, which I am sure that some of you would still think of as small-time, but it’s at the point where the long migration trees are hard for me to wrangle, and running the migrations from scratch eats materially into CI/testing time. We are overdue for a cleanup.
I recall that this discussion has popped up at least a couple of times on django-developers
from the perspective of how to fix the UX for cleaning up migrations, which some have called “less than ideal” (and I am inclined to agree). I do not recall these discussions getting anywhere. However now I am having these issues first hand as a Django user, so i am looking at it as more of a support query. My apologies if this has been brought up elsewhere here. I assumed that it had and did some digging beforehand, but it’s of course a bit hard to search for.
Some additional pieces of info:
- Our project-level application migration dependency trees are highly intermingled (i.e. there are lot of cross-app table relationships).
- Our development team is only two people. The solution does not have to be smooth enough to just work with a
manage.py migrate
. That is to say that myself and the other developer will happily put some manual work into getting things working in our respective developer environments. - It is acceptable to blow away all development databases, though I don’t see why that’d be necessary as replacement migrations could be faked. It’s obviously not acceptable to blow away the prod database.
- There are no data migrations that need to survive (i.e. they are essentially noops when run on a clean database).
I am aware of migration squashing, though I do not have much experience with it. I am aware that it has shortcomings, and is still probably involves a fair bit of work in my situation, so if anything I am looking for assurance that it is (or is not) the right thing to do.
I naively thought that I could just delete all of my migrations and run a manage.py makemigrations
to have Django rebuild them from scratch based on the current state of my model definitions. Last time I tried that—which was not recently but I doubt that anything has changed because this is a fundamental issue—circular dependencies in my model relationships made that impossible. Attempting to selectively comment out relationship fields in my model definitions in order to make intermediary migrations would cause system checks to fail which’d block makemigrations
, etc. All solvable problems, but all requiring effort, so I don’t want to go down this path if someone has a a better/easier idea.
If you were in my position, what would you do?