﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23275	Migrations - unmanaged models doesn't get autodetected	Mārtiņš Šulcs	Andrew Godwin	"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
}}}
"	Bug	closed	Migrations	1.7-rc-2	Release blocker	fixed		cmawebsite@…	Accepted	0	0	0	0	0	0
