#22395: Deleting a model and fields that relate to it results in ValueError:
Related model '<app>.<model>' cannot be resolved
----------------------------+------------------------
     Reporter:  melinath    |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.7-beta-1
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+------------------------
 This seems to happen because a single migration is created which both
 deletes the model and the fields that reference it - but the fields are
 (sometimes?) deleted second, so the model is already "gone" by the time
 the migration gets that far.

 Workaround is to move the field deletions up in the migrations file to
 *before* the model deletion.


 Generated migration (relevant bits):
 {{{
 [...]
 class Migration(migrations.Migration):

     operations = [

         migrations.DeleteModel(
             name='House',
         ),
         migrations.RemoveField(
             model_name='housingslot',
             name='house',
         ),
         migrations.RemoveField(
             model_name='person',
             name='house',
         ),
     ]

 }}}

 Traceback:

 {{{
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File ".../django/django/core/management/__init__.py", line 427, in
 execute_from_command_line
     utility.execute()
   File ".../django/django/core/management/__init__.py", line 419, in
 execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File ".../django/django/core/management/base.py", line 288, in
 run_from_argv
     self.execute(*args, **options.__dict__)
   File ".../django/django/core/management/base.py", line 337, in execute
     output = self.handle(*args, **options)
   File ".../django/django/core/management/commands/migrate.py", line 145,
 in handle
     executor.migrate(targets, plan, fake=options.get("fake", False))
   File ".../django/django/db/migrations/executor.py", line 60, in migrate
     self.apply_migration(migration, fake=fake)
   File ".../django/django/db/migrations/executor.py", line 94, in
 apply_migration
     migration.apply(project_state, schema_editor)
   File ".../django/django/db/migrations/migration.py", line 97, in apply
     operation.database_forwards(self.app_label, schema_editor,
 project_state, new_state)
   File ".../django/django/db/migrations/operations/fields.py", line 36, in
 database_forwards
     field,
   File ".../django/django/db/backends/sqlite3/schema.py", line 117, in
 add_field
     self._remake_table(model, create_fields=[field])
   File ".../django/django/db/backends/sqlite3/schema.py", line 84, in
 _remake_table
     self.create_model(temp_model)
   File ".../django/django/db/backends/schema.py", line 191, in
 create_model
     definition, extra_params = self.column_sql(model, field)
   File ".../django/django/db/backends/schema.py", line 108, in column_sql
     db_params = field.db_parameters(connection=self.connection)
   File ".../django/django/db/models/fields/related.py", line 1758, in
 db_parameters
     return {"type": self.db_type(connection), "check": []}
   File ".../django/django/db/models/fields/related.py", line 1749, in
 db_type
     rel_field = self.related_field
   File ".../django/django/db/models/fields/related.py", line 1655, in
 related_field
     return self.foreign_related_fields[0]
   File ".../django/django/db/models/fields/related.py", line 1414, in
 foreign_related_fields
     return tuple(rhs_field for lhs_field, rhs_field in
 self.related_fields)
   File ".../django/django/db/models/fields/related.py", line 1401, in
 related_fields
     self._related_fields = self.resolve_related_fields()
   File ".../django/django/db/models/fields/related.py", line 1386, in
 resolve_related_fields
     raise ValueError('Related model %r cannot be resolved' % self.rel.to)
 ValueError: Related model 'brambling.House' cannot be resolved
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22395>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.6d8967cb8b583e3b56ec5519b149f5f6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to