# Django 5.1 - AlterIndexTogether raising TypeError: 'class Meta' got invalid attribute(s): index\_together

**URL:** https://forum.djangoproject.com/t/django-5-1-alterindextogether-raising-typeerror-class-meta-got-invalid-attribute-s-index-together/36450
**Category:** ORM
**Created:** [November 15, 2024, 12:06pm UTC](https://forum.djangoproject.com/t/django-5-1-alterindextogether-raising-typeerror-class-meta-got-invalid-attribute-s-index-together/36450 "2024-11-15T12:06:36Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![charettes](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/charettes/32/27_2.png) [@charettes](https://forum.djangoproject.com/u/charettes)
#### Post date: [November 15, 2024, 8:06pm UTC](https://forum.djangoproject.com/t/django-5-1-alterindextogether-raising-typeerror-class-meta-got-invalid-attribute-s-index-together/36450/3 "2024-11-15T20:06:28Z")

</div>

I also think that delegating to `AddIndex` and `RemoveIndex` is the way forward. The fact `AlterIndexTogether` was kept around while raising an unhelpful `TypeError` instead of producing some instructions about how the problem can be solved appears to have been an oversight?

We can’t have `AlterIndexTogether.reduce` to `list[type[AddIndex] | type[RemoveIndex]]` because it requires _knowledge_ about the current project state and one of the flaw of `AlterTogether` operations is that they don’t treat indices as CRUD atoms so there’s no way for the optimization logic to know in which context (which indices exists prior to the optimization) the operation is being reduced. In other words, there’s no way to have `squashmigrations` get rid of `AlterIndexTogether` that I know of; the shim will have to be kept around for the foreseeable future.

We can definitely adapt `AlterIndexTogether.state_forwards` and `.database_(forwards|backwards)` to delegate to `AddIndex` and `RemoveIndex` by introspecting `state` and `from_state` though.

Whichever solution we decide to go forward with should serve as a validation for attempting the same deprecation path on `unique_together -> constraints`.

---

_[View the full topic](https://forum.djangoproject.com/t/django-5-1-alterindextogether-raising-typeerror-class-meta-got-invalid-attribute-s-index-together/36450)._
