As stated in the warning, this happens either :
- When you're using a model which is not in an
INSTALLED_APPS
;
- Or when you're using a model before its application is loaded.
Since you did refer the app in the INSTALLED_APPS
setting, this is most likely you're using a model before the app initialisation.
Typically, this occurs when you have from .models import SomeModels
in an apps.py early signal (for example post_migrate
).
Instead of referring your models the classic way here, it is recommended to use AppConfig.get_model().
Check your apps.py file for any model import, and replace them using this api.
For example instead of :
# apps.py
from django.apps import AppConfig
from .models import MyModel
def do_stuff(sender, **kwargs):
MyModel.objects.get() # etc...
class MyAppConfig(AppConfig):
name = 'src.my_app_label'
def ready(self):
post_migrate.connect(do_stuff, sender=self)
Do this :
# apps.py
from django.apps import AppConfig
def do_stuff(sender, **kwargs):
mymodel = sender.get_model('MyModel')
mymodel.objects.get() # etc...
class MyAppConfig(AppConfig):
name = 'src.my_app_label'
def ready(self):
post_migrate.connect(do_stuff, sender=self)
Note this enforcement was introduced in bug #21719.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…