Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#22342 closed Bug (worksforme)

Changing a model to an abstract model caused "ValueError: Related model 'app.Model' cannot be resolved"

Reported by: Daniel Hahler Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have just run into an error with migrate.

I had turned an existing model (which had a database table already) into a abstract base for others.

The generated migration was, and removing it from the migration worked around the problem:

migrations.DeleteModel(
    name='Model',
),
  Applying app.0016_auto_20140326_1723...Traceback (most recent call last):
  File "…/manage.py", line 62, in <module>
    execute_from_command_line(sys.argv)
  File "…/django-master/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "…/django-master/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "…/django-master/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "…/django-master/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "…/django-master/django/core/management/commands/migrate.py", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "…/django-master/django/db/migrations/executor.py", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "…/django-master/django/db/migrations/executor.py", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "…/django-master/django/db/migrations/migration.py", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "…/django-master/django/db/migrations/operations/fields.py", line 83, in database_forwards
    schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
  File "…/django-master/django/db/backends/schema.py", line 443, in remove_field
    if field.db_parameters(connection=self.connection)['type'] is None:
  File "…/django-master/django/db/models/fields/related.py", line 1758, in db_parameters
    return {"type": self.db_type(connection), "check": []}
  File "…/django-master/django/db/models/fields/related.py", line 1749, in db_type
    rel_field = self.related_field
  File "…/django-master/django/db/models/fields/related.py", line 1655, in related_field
    return self.foreign_related_fields[0]
  File "…/django-master/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-master/django/db/models/fields/related.py", line 1401, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "…/django-master/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 'app.Model' cannot be resolved

It might be somewhat related to bug #22319.

Change History (2)

comment:1 by Baptiste Mispelon, 11 years ago

Resolution: worksforme
Status: newclosed

Hi,

I can't seem to be able to reproduce this.

I've tried creating a (non-abstract) model, running makemigrations and migrate, then changing the model to have abstract=True and running makemigrations and migrate again.

When I do that, I don't get the error you mention.

Could you provide us with the models you used (or better yet, a simplified version that still reproduces the issue)?

Thanks.

comment:2 by Daniel Hahler, 11 years ago

Thanks for looking into this.

I have came across a code comment, where I've linked to this ticket, but the code itself changed quite a lot already.

IIRC your basic test case was what I was doing.

Feel free to close this ticket because of lacking information, and because it has been fixed in the meantime already or was specific to some certain local-only change at that time.

Note: See TracTickets for help on using tickets.
Back to Top