#29000: RenameModel does not rename M2M column when run after
AlterField/RenameField
-------------------------------------+------------------------------------
Reporter: David Nelson Adamec | Owner: Jeff
Type: Bug | Status: assigned
Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Jeff):
* owner: (none) => Jeff
* status: new => assigned
Comment:
Unsurprisingly, this bug also breaks backwards migrations, as the names in
the bridge table don't match expected values.
For the models/migrations in the tickets description, backwards migrations
produces the expected result:
{{{
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/__init__.py",
line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/__init__.py",
line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/base.py",
line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/base.py",
line 331, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/base.py",
line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/core/management/commands/migrate.py",
line 203, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/executor.py",
line 121, in migrate
state = self._migrate_all_backwards(plan, full_plan, fake=fake)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/executor.py",
line 196, in _migrate_all_backwards
self.unapply_migration(states[migration], migration, fake=fake)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/executor.py",
line 262, in unapply_migration
state = migration.unapply(state, schema_editor)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/migration.py",
line 175, in unapply
operation.database_backwards(self.app_label, schema_editor,
from_state, to_state)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/operations/models.py",
line 377, in database_backwards
self.database_forwards(app_label, schema_editor, from_state, to_state)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/migrations/operations/models.py",
line 349, in database_forwards
to_field,
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/base/schema.py",
line 508, in alter_field
return self._alter_many_to_many(model, old_field, new_field, strict)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/base/schema.py",
line 863, in _alter_many_to_many
new_field.remote_field.through._meta.get_field(new_field.m2m_reverse_field_name()),
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/base/schema.py",
line 523, in alter_field
old_db_params, new_db_params, strict)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/base/schema.py",
line 605, in _alter_field
self.execute(self._rename_field_sql(model._meta.db_table, old_field,
new_field, new_type))
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/base/schema.py",
line 133, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/utils.py",
line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/utils.py",
line 68, in execute
return self._execute_with_wrappers(sql, params, many=False,
executor=self._execute)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/utils.py",
line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/utils.py",
line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/utils.py", line
89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/utils.py",
line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.6/dist-
packages/Django-2.1.dev20180514000620-py3.6.egg/django/db/backends/mysql/base.py",
line 71, in execute
return self.cursor.execute(query, args)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 250, in
execute
self.errorhandler(self, exc, value)
File "/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 50,
in defaulterrorhandler
raise errorvalue
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 247, in
execute
res = self._query(query)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 411, in
_query
rowcount = self._do_query(q)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 374, in
_do_query
db.query(q)
File "/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 292,
in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1054, "Unknown column
'modelbrenamed_id' in 'temp_modelc_b_set'")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29000#comment:8>
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/065.3e3c31aeac86754a49f124dcedbf2f26%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.