Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23275 closed Bug (fixed)

Migrations - unmanaged models doesn't get autodetected

Reported by: Mārtiņš Šulcs Owned by: Andrew Godwin
Component: Migrations Version: 1.7-rc-2
Severity: Release blocker Keywords:
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Running migration with fk to unmanaged model fails with ValueError.

Models:

from django.db import models


class SomeModel(models.Model):
    unmanaged_rel = models.OneToOneField('UnmanagedModel', null=True)


class UnmanagedModel(models.Model):
    some_field = models.TextField()
    
    class Meta:
        managed = False

Autogenreated migration:

class Migration(migrations.Migration):

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='SomeModel',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('unmanaged_rel', models.OneToOneField(null=True, to='testproj.UnmanagedModel')),
            ],
            options={
            },
            bases=(models.Model,),
        ),
    ]

Stacktrace:

  Applying testproj.0001_initial...Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/martins/Projects/django-playground/django/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/martins/Projects/django-playground/django/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/martins/Projects/django-playground/django/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/martins/Projects/django-playground/django/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/martins/Projects/django-playground/django/django/core/management/commands/migrate.py", line 160, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 91, in apply_migration
    if self.detect_soft_applied(migration):
  File "/home/martins/Projects/django-playground/django/django/db/migrations/executor.py", line 135, in detect_soft_applied
    apps = project_state.render()
  File "/home/martins/Projects/django-playground/django/django/db/migrations/state.py", line 89, in render
    model=lookup_model,
ValueError: Lookup failed for model referenced by field testproj.SomeModel.unmanaged_rel: testproj.UnmanagedModel

Change History (8)

comment:1 by Mārtiņš Šulcs, 10 years ago

Type: UncategorizedBug

comment:2 by Collin Anderson, 10 years ago

Cc: cmawebsite@… added
Severity: NormalRelease blocker

setting as unreviewed release blocker.

comment:3 by Baptiste Mispelon, 10 years ago

Triage Stage: UnreviewedAccepted

Yes, this does appear to be a serious issue.

Thanks.

comment:4 by Collin Anderson, 10 years ago

I can reproduce it using the models above.

comment:5 by Andrew Godwin, 10 years ago

Yeah, this is valid, the autodetector ignores unmanaged models. I'm pretty sure there's a reasonable fix, similar to the handling of proxy models.

comment:6 by Andrew Godwin, 10 years ago

Owner: changed from nobody to Andrew Godwin
Status: newassigned

comment:7 by Andrew Godwin <andrew@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 8f9862cd4d0e9706babf947079739fd476455df7:

Fixed #23275: Unmanaged models kept by autodetector, ignored by ops

comment:8 by Andrew Godwin <andrew@…>, 10 years ago

In 72fdd62e93cf8bc3a6bfad4d24b06a474ad56942:

[1.7.x] Fixed #23275: Unmanaged models kept by autodetector, ignored by ops

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