Migrations fail if a relation field is added where a non-rel field was
|Reported by:||melinath||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Scenario is this: I have deleted a CharField with choices and replaced it with a ForeignKey to a new table. When Django tries to detect whether this is a "rename", it chokes because it *assumes* that any rel field that was added and might have been renamed was previously *also* a rel field.
Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File ".../django/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File ".../django/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File ".../django/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File ".../django/django/core/management/base.py", line 337, in execute output = self.handle(*args, **options) File ".../django/django/core/management/commands/makemigrations.py", line 99, in handle changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None) File ".../django/django/db/migrations/autodetector.py", line 33, in changes changes = self._detect_changes() File ".../django/django/db/migrations/autodetector.py", line 272, in _detect_changes old_rel_to = old_field_dec['to'] KeyError: 'to'
Should be easy fix - just changing this:
if field.rel and field.rel.to: old_rel_to = old_field_dec['to']
if field.rel and field.rel.to and 'to' in old_field_dec: old_rel_to = old_field_dec['to']
Change History (5)
comment:1 Changed 3 years ago by
|Patch needs improvement:||unset|