#22605: Impossible to delete two models with a M2M field
---------------------------------+--------------------
     Reporter:  andrewgodwin     |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Migrations       |    Version:  master
     Severity:  Release blocker  |   Keywords:
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+--------------------
 In playing around with some test code, I removed the following models and
 made a migration to delete them:

 {{{

 class Table1(models.Model):
     pass

 class Table2(models.Model):
     m2m = models.ManyToManyField(Table1, through='M2M', blank=True)

 class M2M(models.Model):
     t1 = models.ForeignKey(Table1, related_name='+')
     t2 = models.ForeignKey(Table2, related_name='+')
 }}}

 The resulting deletion is impossible, as Table2 and M2M have a circular
 dependency and the "lookup failed" code means you can never get past the
 migration with errors such as:

 {{{
   Applying polls.0005_auto_20140509_0258...Traceback (most recent call
 last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/home/andrew/Programs/Django/django/core/management/__init__.py",
 line 427, in execute_from_command_line
     utility.execute()
   File "/home/andrew/Programs/Django/django/core/management/__init__.py",
 line 419, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/andrew/Programs/Django/django/core/management/base.py", line
 288, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/andrew/Programs/Django/django/core/management/base.py", line
 337, in execute
     output = self.handle(*args, **options)
   File
 "/home/andrew/Programs/Django/django/core/management/commands/migrate.py",
 line 146, in handle
     executor.migrate(targets, plan, fake=options.get("fake", False))
   File "/home/andrew/Programs/Django/django/db/migrations/executor.py",
 line 62, in migrate
     self.apply_migration(migration, fake=fake)
   File "/home/andrew/Programs/Django/django/db/migrations/executor.py",
 line 96, in apply_migration
     migration.apply(project_state, schema_editor)
   File "/home/andrew/Programs/Django/django/db/migrations/migration.py",
 line 107, in apply
     operation.database_forwards(self.app_label, schema_editor,
 project_state, new_state)
   File
 "/home/andrew/Programs/Django/django/db/migrations/operations/models.py",
 line 80, in database_forwards
     apps = from_state.render()
   File "/home/andrew/Programs/Django/django/db/migrations/state.py", line
 94, in render
     extra_message=extra_message,
 ValueError: Lookup failed for model referenced by field polls.Table2.m2m:
 polls.M2M
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22605>
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/055.d02f458e442b07b525d08981a428fbfc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to