﻿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
29466	"Textual ""to"" parameter of ForeignKey fails to resolve if placed in abstract model"	Vitalik Verhovodov	nobody	"{{{#!python
import django
from django.conf import settings

settings.configure(DEBUG=True)
django.setup()

from django.db import models


SHOULD_I_FAIL = True  # switch this to reproduce the bug


class ReferencedModel(models.Model):
    field = models.FloatField()

    class Meta:
        app_label = 'myapp'


ref = 'ReferencedModel' if SHOULD_I_FAIL else ReferencedModel


class AbstractModel(models.Model):
    # NOTE: only abstract models are affected
    field = models.ForeignKey(ref, on_delete=models.CASCADE)

    class Meta:
        abstract = True
        app_label = 'myapp'


class RealModel(AbstractModel):
    other_field = models.CharField(max_length=100)

    class Meta:
        app_label = 'myapp'


ffield = AbstractModel._meta.get_field('field')
# ValueError: Related model 'ReferencedModel' cannot be resolved
print(ffield.target_field)
}}}
"	Bug	new	Database layer (models, ORM)	2.0	Normal				Accepted	0	0	0	0	0	0
