﻿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
35654	SystemCheckError on GenericRelation with lazy reference	Giannis Terzopoulos		"Let's consider having 2 apps, `core` and `bookmarks`. Then I add a new `TaggedItem` model to `core`:
{{{#!python
class TaggedItem(models.Model):
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey()
}}}

and a new `Bookmark` model to `bookmarks`:
{{{#!python
class Bookmark(models.Model):
    tags = GenericRelation('core.TagedItem')
}}}

Running `makemigrations` here I am getting:
{{{
SystemCheckError: System check identified some issues:

ERRORS:
<function GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors at 0x7a08cdb98e00>: (models.E022) <function GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors at 0x7a08cdb98e00> contains a lazy reference to core.tageditem, but app 'core' doesn't provide model 'tageditem'.
bookmarks.Bookmark.tags: (fields.E307) The field bookmarks.Bookmark.tags was declared with a lazy reference to 'core.tageditem', but app 'core' doesn't provide model 'tageditem'.
}}}

The same happens if I `makemigrations` after adding TaggedItem, then add Bookmark and run `makemigrations` again.
It doesn't happen if I `migrate` for TaggedItem, then add Bookmark and `makemigrations`.

It also doesn't happen if I import `TaggedItem` and use that in `GenericRelation`:
{{{#!python
from core.models import TaggedItem


class Bookmark(models.Model):
    tags = GenericRelation(TaggedItem)
}}}

The downside of this in my initial use case was that I would have to work around circular import errors, which wasn't easily doable. 

Finally, having both models in the same app/models.py and using the ''lazy reference'' GenericRelation doesn't trigger the error either. So it seems to me as if something is missing here."	Bug	closed	Database layer (models, ORM)	5.0	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
