﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22833	"1.7 migrations can't delete codependent ""through"" models"	mozumder@…	nobody	"Hi,

I'm using Django 1.7b4, and I'm testing the migrations.  I have this existing model in the database:


{{{
class BlocksList(Named, Ordered):
    blocks_list_assignments = models.ManyToManyField(
                                          Block,
                                          through='BlocksListAssignment'
                                          )
    family = models.ForeignKey(
        BlockFamily,
        verbose_name=_(""Family Name""),
        null=True,
        blank=True,
        )
    def __str__(self):  # Python 3: def __str__(self):
        return self.name


class BlocksListAssignment(Ordered):
    block = models.ForeignKey(Block)
    block_list = models.ForeignKey(BlocksList)
    def __str__(self):  # Python 3: def __str__(self):
        return self.block_list.name + "": %s"" % self.block

}}}

I'm trying to delete this with the makemigrations/migrate command, with this in my migrations file:


{{{
        migrations.DeleteModel(
            name='BlocksList',
        ),
        migrations.DeleteModel(
            name='BlocksListAssignment',
        ),

}}}

It looks like the co-dependencies prevent the migrations from deleting both models, because I constantly get:

{{{

Running migrations:
  Applying blocks.0014_auto_20140613_2227...Traceback (most recent call last):
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/apps/config.py"", line 152, in get_model
    return self.models[model_name.lower()]
KeyError: 'blockslistassignment'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/state.py"", line 76, in render
    model = self.apps.get_model(lookup_model[0], lookup_model[1])
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/apps/registry.py"", line 190, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/apps/config.py"", line 155, in get_model
    ""App '%s' doesn't have a '%s' model."" % (self.label, model_name))
LookupError: App 'blocks' doesn't have a 'blockslistassignment' model.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/__init__.py"", line 427, in execute_from_command_line
    utility.execute()
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/__init__.py"", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/commands/migrate.py"", line 146, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/executor.py"", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/executor.py"", line 90, in apply_migration
    if self.detect_soft_applied(migration):
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/executor.py"", line 134, in detect_soft_applied
    apps = project_state.render()
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/migrations/state.py"", line 86, in render
    model=lookup_model,
ValueError: Lookup failed for model referenced by field blocks.BlocksList.blocks_list_assignments: blocks.BlocksListAssignment

}}}

Anyways to get around this I have to recreate the database and start from fixtures.

Do let me know if there is another way where I can use the migrations directly.

This is on Mac OS X 10.9, Python 3.4.0, Django 1.7b4, and PostGRES 9.3.4 database."	Bug	closed	Migrations	1.7-beta-2	Release blocker	fixed			Accepted	0	0	0	0	0	0
