#23859: Renaming a field in a index_together fails
----------------------------+---------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------
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'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.6acc0e0a197830bf93746b58c2870966%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.