Django "Model class ... doesn't declare an explicit app_label" in CI
Django could not attach a model to any installed app. Either the app is missing from INSTALLED_APPS, or the module defining the model was imported directly (before setup) so Django cannot infer its app label.
What this error means
Import or setup fails with "RuntimeError: Model class app.models.Thing doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS."
RuntimeError: Model class app.models.Thing doesn't declare an explicit app_label
and isn't in an application in INSTALLED_APPS.Common causes
The app is not in INSTALLED_APPS
The model lives in an app that the CI settings module never lists, so Django cannot associate it with an app label.
The models module was imported too early or by the wrong path
Importing models.py directly (or before django.setup()) means Django never registered the app, so the label cannot be inferred.
How to fix it
Register the app in INSTALLED_APPS
- Confirm the app config or app name is listed in INSTALLED_APPS.
- Make sure the CI settings module inherits the same app list as dev.
- Import models through the app package, not by file path.
INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.auth",
"app.apps.AppConfig",
]Set an explicit app_label if needed
For a model defined outside a conventional app package, declare the label on its Meta.
class Thing(models.Model):
class Meta:
app_label = "app"How to prevent it
- Keep INSTALLED_APPS identical between dev and CI settings.
- Import models via the app package after django.setup().
- Avoid running model files as standalone scripts.