Django model “doesn't declare an explicit app_label”

后端 未结 28 1904
無奈伤痛
無奈伤痛 2020-11-27 15:38

I\'m at wit\'s end. After a dozen hours of troubleshooting, probably more, I thought I was finally in business, but then I got:

Model class django.contrib.co         


        
28条回答
  •  余生分开走
    2020-11-27 16:16

    I got this error on importing models in tests, i.e. given this Django project structure:

    |-- myproject
        |-- manage.py
        |-- myproject
        |-- myapp
            |-- models.py  # defines model: MyModel
            |-- tests
                |-- test_models.py
    

    in file test_models.py I imported MyModel in this way:

    from models import MyModel
    

    The problem was fixed if it is imported in this way:

    from myapp.models import MyModel
    

    Hope this helps!

    PS: Maybe this is a bit late, but I not found in others answers how to solve this problem in my code and I want to share my solution.

提交回复
热议问题