﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35679	Existing old migrations with migrations.AlterIndexTogether seem to break after Django 5.1	Simon Willison		"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."	Uncategorized	closed	Migrations	5.1	Normal	duplicate			Unreviewed	0	0	0	0	0	0
