RemovedInDjango19Warning: Model doesn't declare an explicit app_label

后端 未结 2 1302
旧巷少年郎
旧巷少年郎 2021-01-04 18:39

Have gone through

Django 1.9 deprecation warnings app_label

but answers couldn\'t fix my problem, so asking again.

I have an app that is added to IN

相关标签:
2条回答
  • 2021-01-04 19:10

    You are importing models.py before app configuration run.

    To fix it, you could import and configure signals in CatalogConfig.ready method.

    like this:

    signals.py

    def someSignal(sender, **kwargs):
        pass
    

    apps.py

    from django.apps import AppConfig
    from django.db.models.signals import post_save
    
    
    class CatalogConfig(AppConfig):
        name = 'catalog'
        verbose_name = 'Catalogue'
    
        def ready(self):
            from .signals import someSignal
            post_save.connect(
                receiver=someSignal,
                sender=self.get_model('Category')
            )
    

    you may want to check ready method in documentation

    0 讨论(0)
  • 2021-01-04 19:22

    I experienced this issue when running tests and it was simply a matter of changing:

    from .models import MyModel
    

    to

    from apps.myapp.models import MyModel
    
    0 讨论(0)
提交回复
热议问题