#23160: KeyError when performing a RenameModel migration operation for a model 
with
self-referential FK field
---------------------------------+--------------------------------------
     Reporter:  whitews@…        |                    Owner:  charettes
         Type:  Bug              |                   Status:  assigned
    Component:  Migrations       |                  Version:  1.7-rc-2
     Severity:  Release blocker  |               Resolution:
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Changes (by charettes):

 * status:  new => assigned
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * owner:  nobody => charettes
 * needs_docs:   => 0
 * severity:  Normal => Release blocker


Old description:

> I'm simply trying to rename a model which has a relationship to itself.
> Running the RenameModel operation yields the following traceback:
>
> $ python manage.py migrate myapp
> Operations to perform:
>   Apply all migrations: myapp
> Running migrations:
>   Applying myapp.0002_rename_Foo_to_Bar...Traceback (most recent call
> last):
>   File "manage.py", line 10, in <module>
>     execute_from_command_line(sys.argv)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/core/management/__init__.py", line
> 385, in execute_from_command_line
>     utility.execute()
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/core/management/__init__.py", line
> 377, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/core/management/base.py", line
> 288, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/core/management/base.py", line
> 338, in execute
>     output = self.handle(*args, **options)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/core/management/commands/migrate.py",
> line 160, in handle
>     executor.migrate(targets, plan, fake=options.get("fake", False))
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
> 63, in migrate
>     self.apply_migration(migration, fake=fake)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
> 91, in apply_migration
>     if self.detect_soft_applied(migration):
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
> 134, in detect_soft_applied
>     project_state = self.loader.project_state((migration.app_label,
> migration.name), at_end=True)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/loader.py", line
> 268, in project_state
>     return self.graph.make_state(nodes=nodes, at_end=at_end,
> real_apps=list(self.unmigrated_apps))
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/graph.py", line 147,
> in make_state
>     project_state = self.nodes[node].mutate_state(project_state)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/migration.py", line
> 76, in mutate_state
>     operation.state_forwards(self.app_label, new_state)
>   File "/usr/local/lib/python2.7/dist-
> packages/Django-1.7c2-py2.7.egg/django/db/migrations/operations/models.py",
> line 132, in state_forwards
>     for name, field in state.models[related_key].fields:
> KeyError: ('myapp', 'foo')

New description:

 I'm simply trying to rename a model which has a relationship to itself.
 Running the RenameModel operation yields the following traceback:

 {{{
 $ python manage.py migrate myapp
 Operations to perform:
   Apply all migrations: myapp
 Running migrations:
   Applying myapp.0002_rename_Foo_to_Bar...Traceback (most recent call
 last):
   File "manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/core/management/__init__.py", line
 385, in execute_from_command_line
     utility.execute()
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/core/management/__init__.py", line
 377, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/core/management/base.py", line 288,
 in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/core/management/base.py", line 338,
 in execute
     output = self.handle(*args, **options)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/core/management/commands/migrate.py",
 line 160, in handle
     executor.migrate(targets, plan, fake=options.get("fake", False))
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
 63, in migrate
     self.apply_migration(migration, fake=fake)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
 91, in apply_migration
     if self.detect_soft_applied(migration):
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/executor.py", line
 134, in detect_soft_applied
     project_state = self.loader.project_state((migration.app_label,
 migration.name), at_end=True)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/loader.py", line 268,
 in project_state
     return self.graph.make_state(nodes=nodes, at_end=at_end,
 real_apps=list(self.unmigrated_apps))
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/graph.py", line 147,
 in make_state
     project_state = self.nodes[node].mutate_state(project_state)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/migration.py", line
 76, in mutate_state
     operation.state_forwards(self.app_label, new_state)
   File "/usr/local/lib/python2.7/dist-
 packages/Django-1.7c2-py2.7.egg/django/db/migrations/operations/models.py",
 line 132, in state_forwards
     for name, field in state.models[related_key].fields:
 KeyError: ('myapp', 'foo')
 }}}

--

Comment:

 Reproduced against master.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23160#comment:1>
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/075.01b91ec730932d4814e11fd3d99d056f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to