Skip to content

Conversation

@nzioker
Copy link
Contributor

@nzioker nzioker commented Oct 28, 2025

Trac ticket number

Fixed #36632

Branch description

Problem

AlterIndexTogether in historical migrations was dropping overlapping indexes when changing from [('a', 'b')] to [('a', 'b'), ('a', 'b', 'c')].

Root Cause

  • alter_index_together used news.difference(olds) which only created new indexes
  • _model_indexes_sql didn't include index_together indexes during SQLite table remakes

Solution

  • Changed alter_index_together to iterate over all target indexes (news instead of news.difference(olds))
  • Added historical index_together support to _model_indexes_sql
  • Added regression test

Testing

  • Original reproduction case now works
  • All migration tests pass
  • No regressions introduced

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.

found_abc = True

self.assertTrue(
found_ab, "Index on (a, b) was not found. Indexes: {}".format(index_sql)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test fails for

AssertionError: False is not true : Index on (a, b) was not found. Indexes: {'testapp_mymodel_a_b_221151a1_idx': 'CREATE INDEX testapp_mymodel_a_b_221151a1_idx ON public.testapp_mymodel USING btree (a, b)', 'testapp_mymodel_a_b_c_4f1d0c1a_idx': 'CREATE INDEX testapp_mymodel_a_b_c_4f1d0c1a_idx ON public.testapp_mymodel USING btree (a, b, c)'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants