Recently I splitted an app into two separate ones because I had 15+ models in it. I had got the “circular import error”. To solve this I tried writing this:
from django.db import models
class App1Model(models.Model):
app2model = models.ForeignKey(app2.App2Model)
The error I’m getting is: “NameError: name ‘app2’ is not defined”. But app2 is correctly added into installed apps and into the path.
project
-app1
--models.py
-app2
--models-py
ForeignKeycan take a string as an argument, i.e.models.ForeignKey('app2.App2Model'). Of course, you should try to design your code to avoid any circular dependencies in the first place.