#24828 closed Cleanup/optimization (fixed)
AlterUniqueTogether prevents squashmigrations optimizations
Reported by: | Piotr Maliński | Owned by: | Markus Holtermann |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a model that has a AlterUniqueTogether so in initial migration after CreateModel there was a AlterUniqueTogether operation. After that I got some migrations that add/alter/remove some fields to that model (but not those in AlterUniqueTogether). squashmigrations couldn't optimize those additional operations into one CreateModel operation. When I moved AlterUniqueTogether to the end of the squash operations list and resquashed then it did that. (Django 1.8.1)
Change History (7)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
I can't confirm this can be definitely be fixed, but investigating it seems worthwhile.
comment:3 by , 9 years ago
Version: | 1.8 → master |
---|
Yes, it's possible, but I think it's not a trivial thing like adding another rule to the MigrationOptimizer
(django.db.migrations.optimizer
). AlterFOOTogether
and AlterField
have nothing in common that would require a merge / reordering. Thus it's not picked up, I guess. But that's just from a brief look.
comment:4 by , 9 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
AlterIndexTogether also. I've also noticed that if there are two or more models the optimization is quite fragile to order of operations. When I move all model A simple add/remove/alter operations after CreateModel, then move similar operations after CreateModel B then it will resquash it nicely. If those operations are mixes and CreateModel A, B are at start then it won't merge operations.