﻿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
23859	Renaming a field in a index_together fails	Markus Holtermann	Markus Holtermann	"This issue is almost the same as #23014.

Renaming a field in a model that is part of an `index_together` fails with the same error as in the referenced ticket.

Old model:

{{{#!python
class Foo(models.Model):
    foo = models.IntegerField()
    bar = models.IntegerField(default=42)

    class Meta:
        index_together = (('foo', 'bar'), )
}}}

New model:

{{{#!python
class Foo(models.Model):
    foo = models.IntegerField()
    bar2 = models.IntegerField(default=42)

    class Meta:
        index_together = (('foo', 'bar2'), )
}}}

Traceback:

{{{#!python
Traceback (most recent call last):
  File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/home/markus/Coding/django/django/core/management/__init__.py"", line 338, in execute_from_command_line
    utility.execute()
  File ""/home/markus/Coding/django/django/core/management/__init__.py"", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/markus/Coding/django/django/core/management/base.py"", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/home/markus/Coding/django/django/core/management/base.py"", line 442, in execute
    output = self.handle(*args, **options)
  File ""/home/markus/Coding/django/django/core/management/commands/migrate.py"", line 193, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File ""/home/markus/Coding/django/django/db/migrations/executor.py"", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File ""/home/markus/Coding/django/django/db/migrations/executor.py"", line 97, in apply_migration
    migration.apply(project_state, schema_editor)
  File ""/home/markus/Coding/django/django/db/migrations/migration.py"", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File ""/home/markus/Coding/django/django/db/migrations/operations/models.py"", line 297, in database_forwards
    getattr(new_model._meta, self.option_name, set()),
  File ""/home/markus/Coding/django/django/db/backends/schema.py"", line 320, in alter_index_together
    columns = [model._meta.get_field_by_name(field)[0].column for field in fields]
  File ""/home/markus/Coding/django/django/db/backends/schema.py"", line 320, in <listcomp>
    columns = [model._meta.get_field_by_name(field)[0].column for field in fields]
  File ""/home/markus/Coding/django/django/db/models/options.py"", line 410, in get_field_by_name
    % (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Foo has no field named 'bar'
}}}
"	Bug	closed	Migrations	1.7	Normal	fixed		Markus Holtermann	Accepted	1	0	0	0	0	0
