#35679: Existing old migrations with migrations.AlterIndexTogether seem to break after Django 5.1 --------------------------------+----------------------------------------- Reporter: Simon Willison | Type: Uncategorized Status: new | Component: Migrations Version: 5.1 | Severity: Normal Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 --------------------------------+----------------------------------------- I may be wrong about this, but it appears as if having an existing migration in a Django project that includes something like this: {{{ from django.db import migrations, models
class Migration(migrations.Migration): initial = True dependencies = [] operations = [ migrations.CreateModel( name="SubscriberCount", fields=[ ( "id", models.AutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("path", models.CharField(max_length=128)), ("count", models.IntegerField()), ("created", models.DateTimeField(auto_now_add=True)), ("user_agent", models.CharField(db_index=True, max_length=128)), ], ), migrations.AlterIndexTogether( name="subscribercount", index_together=set([("path", "user_agent", "count", "created")]), ), ] }}} No longer works in the latest Django (I think since 5.1) - attempts to run migrations produce errors that look like this: {{{ File "/Users/simon/.local/share/virtualenvs/simonwillisonblog- izSE3ZQu/lib/python3.10/site-packages/django/db/models/base.py", line 371, in add_to_class value.contribute_to_class(cls, name) File "/Users/simon/.local/share/virtualenvs/simonwillisonblog- izSE3ZQu/lib/python3.10/site-packages/django/db/models/options.py", line 220, in contribute_to_class raise TypeError( TypeError: 'class Meta' got invalid attribute(s): index_together }}} If I'm right, this is happening because `index_together` was deprecated and removed from Django. The problem is that this means projects with existing migrations can no longer run. Potential solutions here: 1. Make sure `index_together` in older migrations does not cause an error. 2. Provide documentation describing how to repair projects which are affected by this bug. I hacked around it with some rough commenting out of code in old migrations but I'm not at all confident it was the right thing to do: https://github.com/simonw/simonwillisonblog/pull/480/commits/f0aa2d69ddeca2acf7badc9ec68dfb7c5b0086ab 3. A combination of the above - make sure it works, but also document what people should do in an upgrade scenario. -- Ticket URL: <https://code.djangoproject.com/ticket/35679> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/010701914e2d0e2f-28dc7291-e3f0-48ea-b480-45df29b1bc0e-000000%40eu-central-1.amazonses.com.