#23938: changing a ManyToManyField to a CharField while also deleting the model
being connected to breaks migrations
-------------------------------+--------------------
     Reporter:  hoylemd        |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.7
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 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

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

Reply via email to