Django model “doesn't declare an explicit app_label”

后端 未结 28 1920
無奈伤痛
無奈伤痛 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:08

    In my case I got this error when porting code from Django 1.11.11 to Django 2.2. I was defining a custom FileSystemStorage derived class. In Django 1.11.11 I was having the following line in models.py:

    from django.core.files.storage import Storage, DefaultStorage
    

    and later in the file I had the class definition:

    class MyFileStorage(FileSystemStorage):
    

    However, in Django 2.2 I need to explicitly reference FileSystemStorage class when importing:

    from django.core.files.storage import Storage, DefaultStorage, FileSystemStorage
    

    and voilà!, the error dissapears.

    Note, that everyone is reporting the last part of the error message spitted by Django server. However, if you scroll up you will find the reason in the middle of that error mambo-jambo.

提交回复
热议问题