#34525: index_together warning after migration to new style
-------------------------------------+-------------------------------------
Reporter: Mateusz Legięcki | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: index_together, | Triage Stage: Accepted
warning |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):
Replying to [comment:17 Simon Charette]:
> Users will have to squash or edit their migration to support the next
release of Django, it is inevitable.
We should implement set of reductions to make it doable for users. I've
prepared a [https://github.com/django/django/compare/main...felixxm
:reduce-index-index-together?expand=1 branch] (no tests and release notes
but I'll be happy to add them) that allows me to optimized a squashed
migration (`0001`-`0004`) in a
[https://gist.github.com/felixxm/bd5bdf6f8950109dd2db40417e2d3d12 quite
complicated situation] from:
{{{
operations = [
migrations.CreateModel(
name='MyModel',
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('field_1', models.IntegerField()),
('field_2', models.TextField()),
('field_3', models.IntegerField()),
('field_4', models.IntegerField(null=True)),
],
options={
'index_together': {('field_2', 'field_4')},
},
),
migrations.AddIndex(
model_name='mymodel',
index=models.Index(fields=['field_1', 'field_2'],
name='test_one_my_field_1_ea7372_idx'),
),
migrations.AddIndex(
model_name='mymodel',
index=models.Index(fields=['field_3'],
name='test_one_my_field_3_d91b6c_idx'),
),
migrations.AddIndex(
model_name='mymodel',
index=models.Index(fields=['field_3', 'field_4'],
name='test_one_my_field_3_1e8bd9_idx'),
),
migrations.RemoveIndex(
model_name='mymodel',
name='test_one_my_field_1_ea7372_idx',
),
migrations.AlterIndexTogether(
name='mymodel',
index_together={('field_1', 'field_2'), ('field_2',
'field_4')},
),
migrations.RenameIndex(
model_name='mymodel',
new_name='test_one_my_field_1_ea7372_idx',
old_fields=('field_1', 'field_2'),
),
migrations.RenameIndex(
model_name='mymodel',
new_name='test_one_my_field_2_26d2ae_idx',
old_fields=('field_2', 'field_4'),
),
]
}}}
into
{{{
operations = [
migrations.CreateModel(
name='MyModel',
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('field_1', models.IntegerField()),
('field_2', models.TextField()),
('field_3', models.IntegerField()),
('field_4', models.IntegerField(null=True)),
],
options={
'indexes': [
models.Index(fields=['field_3'],
name='test_one_my_field_3_d91b6c_idx'),
models.Index(fields=['field_3', 'field_4'],
name='test_one_my_field_3_1e8bd9_idx'),
models.Index(fields=['field_1', 'field_2'],
name='test_one_my_field_1_ea7372_idx'),
models.Index(fields=['field_2', 'field_4'],
name='test_one_my_field_2_26d2ae_idx')
],
},
),
]
}}}
without `index_together` 🎉 As far as I'm aware, once this is implemented
we can start recommending squashing to end users.
--
Ticket URL: <https://code.djangoproject.com/ticket/34525#comment:18>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070187d706f22b-47a2c8c1-2e44-495e-99cb-8a9ef2c42453-000000%40eu-central-1.amazonses.com.