﻿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
25858	Deriving from abstract model with foreign key to model in same app broken on Django 1.9	Karl Hobley	Simon Charette	"As of Django 1.9, it is no longer possible to derive a new model from abstract model in another app if that abstract model has a local foreign key to a model in the same app.

See example project here: https://github.com/kaedroho/djangobugtest


For example, I have two apps: app1 and app2

app1 contains a concrete model and an abstract model. The abstract model has a foreign key to the concrete one (note the Foreign key is defined as a string and doesn't include the app label):

{{{
class ConcreteModel(models.Model):
    pass


class AbstractModel(models.Model):
    foreign_key = models.ForeignKey('ConcreteModel')

    class Meta:
        abstract = True
}}}

In app2, we have another model that derives from the abstract model in app 1

{{{
class DerivedModel(app1.AbstractModel):
    pass
}}}


When running makemigrations, the following system check error occurs:

{{{
app2.DerivedModel.foreign_key: (fields.E300) Field defines a relation with model 'ConcreteModel', which is either not installed, or is abstract.
}}}


For apps upgrading to Django 1.9 and already have migrations, the following error occurs when running tests (after the database has been initialised but before the first test runs. It looks like it's happening while serialising the database):

{{{
ValueError: Related model u'ConcreteModel' cannot be resolved
}}}

Traceback from an actual site: https://gist.github.com/kaedroho/01b29332308018abfa29

This issue only occurs when the ForeignKey is defined with a string that doesn't contain the app label. So referencing the model class directly or using ""app_label.ModelName"" works."	Bug	closed	Database layer (models, ORM)	1.9	Release blocker	fixed		Karl Hobley Simon Charette	Ready for checkin	1	0	0	0	0	0
