mardi 2 avril 2019

How does running a test in PyCharm result in an "Model class doesn't declare an explicit app_label" error?

I'm using Django, Python 3.7, and PyCharm 2018.3.5. I'm trying to run a test in PyCharm by right-clicking on the test name and selecting, "Run Test: 'test name'". This results in the following error

RuntimeError: Model class appname.models.Label doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

This is the model in question, at the top of my models.py file ...

class Label(models.Model):
    name = models.CharField(max_length=200)

    def __str__(self):
        return self.name

    class Meta:
        unique_together = ("name",)

What is very odd is if I run the tests outside of PyCharm (e.g. at a terminal command prompt using "python manage.py test"), everything runs fine. So the problem would seem to be some misconfiguration with PyCharm. I'm unclear how to attack the problem further. Below is my project directory structure ...

appname
    __init__.py
    __pycache__
    admin.py
    apps.py
    fixtures
    management
    migrations
    models.py
    services.py
    static
    templates
    tests.py
    views.py
manage.py
templates
venv
appname_project

Aucun commentaire:

Enregistrer un commentaire