We have a lot of tables in our db which have a lot of category-type fields, and those charfields have a fixed set of choices that have been growing in the history of the project.
First migration:
migrations.CreateModel(
name="...",
fields=[...
(
"transaction_type",
models.CharField(
blank=True,
choices=[
("DD_FIRST_COLLECTION", "Direct debit first collection"),
("DD_REGULAR_COLLECTION", "Direct debit regular collection"),
],
max_length=512,
),
),
And lots of these:
migrations.AlterField(
model_name="accountpayment",
name="transaction_type",
field=models.CharField(
blank=True,
choices=[
("DD_FIRST_COLLECTION", "Direct debit first collection"),
("DD_REGULAR_COLLECTION", "Direct debit regular collection"),
("CREDIT_CARD", "Credit card collection"),
....
I think the right behaviour, during squashmigrations, should be that the migrations optimizer merges these operations back into one. Especially if the second set is a superset of the first one.
Could this be a suggested improvement to the optimizer’s code? or is there a edge case which i am not seeing?