if you have model.py:
class Thing(models.Model):
#fields
class ThingList(models.Model):
things = models.ManyToManyField('Thing')
then run migrations, then change it to:
class ThingList(models.Model):
things = models.CharField(max_length=200)
(note the removal of the Thing model)
and then make migrations, running the migrations fails with
Applying brokenmigration.0002_auto_20141130_2034...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 124, in database_forwards
from_model = from_state.render().get_model(app_label, self.model_name)
File "/home/hoylemd/django-env/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 89, in render
model=lookup_model,
ValueError: Lookup failed for model referenced by field brokenmigration.ThingList.things: brokenmigration.Thing
I have made a github repository demonstrating the behavior: https://github.com/hoylemd/djangomigrationsbug
I'm using version 1.7.1
I classify this as a release blocker since it breaks a new feature introduced in 1.7.