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.
* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Reproducible on both `stable/1.7.x` and `master`
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:1>
* status: new => assigned
* has_patch: 0 => 1
Comment:
Thank you for the confirmation, bak1an.
Here's a pull-request: https://github.com/django/django/pull/3563
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:2>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7b4a994599b75a07cb07d1e0cc26b3bbf25ab7a6"]:
{{{
#!CommitTicketReference repository=""
revision="7b4a994599b75a07cb07d1e0cc26b3bbf25ab7a6"
Fixed #23859 -- Fixed a migration crash when a field is renamed that is
part of an index_together
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:3>
Comment (by Carl Meyer <carl@…>):
In [changeset:"6ae1e3ba9f3a5316504c7543ba4abc472990de95"]:
{{{
#!CommitTicketReference repository=""
revision="6ae1e3ba9f3a5316504c7543ba4abc472990de95"
Merge pull request #3563 from MarkusH/ticket23859
Fixed #23859 -- Fixed a migration crash when a field is renamed that is
part of an index_together
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:4>
Comment (by Carl Meyer <carl@…>):
In [changeset:"03d983f7c39e8ba5b09d4000a234768715f8834f"]:
{{{
#!CommitTicketReference repository=""
revision="03d983f7c39e8ba5b09d4000a234768715f8834f"
[1.7.x] Fixed #23859 -- Fixed a migration crash when a field is renamed
that is part of an index_together
Backport of 7b4a994599b75a07cb07d1e0cc26b3bbf25ab7a6 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:5>
* status: closed => new
* has_patch: 1 => 0
* resolution: fixed =>
Comment:
This is causing a test failure on Oracle:
{{{
======================================================================
ERROR: test_rename_field (migrations.test_operations.OperationTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/code/django/tests/migrations/test_operations.py", line
988, in test_rename_field
project_state = self.set_up_test_model("test_rnfl",
unique_together=True, index_together=True)
File "/home/tim/code/django/tests/migrations/test_operations.py", line
146, in set_up_test_model
return self.apply_operations(app_label, ProjectState(), operations)
File "/home/tim/code/django/tests/migrations/test_operations.py", line
32, in apply_operations
return migration.apply(project_state, editor)
File "/home/tim/code/django/django/db/migrations/migration.py", line
108, in apply
operation.database_forwards(self.app_label, schema_editor,
project_state, new_state)
File "/home/tim/code/django/django/db/migrations/operations/models.py",
line 36, in database_forwards
schema_editor.create_model(model)
File "/home/tim/code/django/django/db/backends/schema.py", line 266, in
create_model
self.execute(self._create_index_sql(model, fields, suffix="_idx"))
File "/home/tim/code/django/django/db/backends/schema.py", line 102, in
execute
cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/tim/code/django/django/db/backends/utils.py", line 65, in
execute
return self.cursor.execute(sql, params)
File "/home/tim/code/django/django/db/backends/oracle/base.py", line
916, in execute
return self.cursor.execute(query, self._param_generator(params))
DatabaseError: ORA-01408: such column list already indexed
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:6>
* has_patch: 0 => 1
Comment:
This issue should be fixed by https://github.com/django/django/pull/3589
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"4c709cc0ef0daa2b527e056865f51796fb0d42f3"]:
{{{
#!CommitTicketReference repository=""
revision="4c709cc0ef0daa2b527e056865f51796fb0d42f3"
Fixed duplicate index error on Oracle; refs #23859.
Refers to regression introduced in
7b4a994599b75a07cb07d1e0cc26b3bbf25ab7a6
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"145467a63688eb9055d176d84655cc029060da30"]:
{{{
#!CommitTicketReference repository=""
revision="145467a63688eb9055d176d84655cc029060da30"
[1.7.x] Fixed duplicate index error on Oracle; refs #23859.
Refers to regression introduced in
7b4a994599b75a07cb07d1e0cc26b3bbf25ab7a6
Backport of 4c709cc0ef0daa2b527e056865f51796fb0d42f3 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:9>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/23859#comment:10>