Opened 10 years ago
Closed 10 years ago
#23859 closed Bug (fixed)
Renaming a field in a index_together fails
Reported by: | Markus Holtermann | Owned by: | Markus Holtermann |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Markus Holtermann | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
class Foo(models.Model): foo = models.IntegerField() bar = models.IntegerField(default=42) class Meta: index_together = (('foo', 'bar'), )
New model:
class Foo(models.Model): foo = models.IntegerField() bar2 = models.IntegerField(default=42) class Meta: index_together = (('foo', 'bar2'), )
Traceback:
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'
Change History (10)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
Has patch: | set |
---|---|
Status: | new → assigned |
Thank you for the confirmation, bak1an.
Here's a pull-request: https://github.com/django/django/pull/3563
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:6 by , 10 years ago
Has patch: | unset |
---|---|
Resolution: | fixed |
Status: | closed → new |
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
comment:7 by , 10 years ago
Has patch: | set |
---|
This issue should be fixed by https://github.com/django/django/pull/3589
comment:10 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Reproducible on both
stable/1.7.x
andmaster