Search code examples
djangopython-3.xcookiecutter-django

RuntimeError: Model class xxx doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS


I refer to following GitHub repo which is based on Django 2.0 and cookiecutter-django: github.com/Apfelschuss/apfelschuss/tree/c8851430201daeb7d1d81c5a6b3c8a639ea27b02

I am getting the following error when trying to run the app:

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

Error appeared with this line of code.

I tried to do as described in https://stackoverflow.com/a/40206661/5894988 but without success:

config/settings/base.py

LOCAL_APPS = [
    "apfelschuss.votes.apps.VotesConfig"
]

apfelschuss/votes/apps.py

from django.apps import AppConfig


class VotesConfig(AppConfig):

    name = "apfelschuss.votes"
    verbose_name = "Votes"

Any idea what I am doing wrong?

If anyone is interested how to run the docker container of the repo. It is described here.


Solution

  • Working with absolute imports in the view solved my issue. I changed .models to apfelschuss.votes.models.

    Code that leads to runtime error:

    from django.shortcuts import render
    
    from .models import Voting
    

    Issue solved with absolute import:

    from django.shortcuts import render
    
    from apfelschuss.votes.models import Voting
    

    See commit on GitHub here.