I’m starting a new django project which I haven’t done in a while and I was imagining building a fairly tightly coupled htmx-models, real modern and simple, I was planning to be so clever.
At the moment, I am stuck because my project hits this error:
"RuntimeError: Model class pysrc.floor.models.Activity doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS."
The model in question is not complicated and is in floor/models.py:
class Activity(models.Model): name = models.CharField(max_length=250) precedence = models.PositiveIntegerField(default=1) target_groups = models.ManyToManyField(Group) parent_activity = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
The ‘floor’ app folder was created with startapp; I’ve added floor.apps.FloorConfig to INSTALLED_APPS and tried it at both ends.
INSTALLED_APPS = [ "floor.apps.FloorConfig", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", ]
Weird stuff that I did/am doing that I don’t think should matter:
- I changed the folder structure to put the django folders under a folder called ‘pysrc’ instead of the project name (‘deep’) - so the settings are in deep.settings, or deep.pysrc.deep.settings in full, and models are in deep.pysrc.floor.models. manage.py is in the pysrc folder: ie
deep |-- pysrc |--deep |--- settings.py, asgi.py etc |--floor |--- models.py, apps.py etc manage.py |-- non-py folders (future docker stuff)
- I am experimenting with creation of models (only at import time) using the type() function (later in the script, not the Activity model)
- I am triggering this error primarily from a test in floor/tests.py (it does also occur for makemigrations etc)