Django 1.9 deprecation warnings app_label Django 1.9 deprecation warnings app_label django django

Django 1.9 deprecation warnings app_label


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.pyfrom django.apps import AppConfigfrom .models import MyModeldef 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.pyfrom django.apps import AppConfigdef 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.


Similar error. In my case the error was:

RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.class Site(models.Model):

My solution was:

Added 'django.contrib.sites' to INSTALLED_APPS


I suspect it'll be only a tiny minority of people who see this error for whom it will be caused by the same thing as me, but in case it helps someone else it seems worth adding this answer!

I suddenly saw lots of these errors when running tests at one point - it turned out that I had accidentally created a __init__.py at the top level of my Django project when it was meant to be in a subdirectory. The clue that this was happening is that the errors, which were like:

/home/mark/mystupiddjangoproject/alerts/models.py:15: RemovedInDjango19Warning: Model class mystupiddjangoproject.alerts.models.Alert doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.  class Alert(models.Model):

... included the name of directory the project is in (mystupiddjangoproject) in the fully qualified model name, which should have been: alerts.models.Alert.

To fix this, I just needed to do:

rm __init__.pyrm __init__.pyc