Skip to content
Latchkey

Django "AppRegistryNotReady: Apps aren't loaded yet" in CI

Django populates its app registry during django.setup(). If a standalone CI script imports models or calls ORM APIs before that, the registry is empty and Django raises AppRegistryNotReady.

What this error means

A migration data step, seed script, or custom runner fails with "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet." even though manage.py commands work.

Django
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Common causes

Models imported before django.setup()

A script imports from app.models import Thing at module top level without configuring Django first, so the app registry has not been built.

ORM access at import time in a helper

A module runs a query or apps.get_model() while being imported, before apps finish loading.

How to fix it

Call django.setup() before importing models

  1. Set DJANGO_SETTINGS_MODULE at the top of the script.
  2. Call django.setup().
  3. Only then import models or touch the ORM.
scripts/seed.py
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings.ci")
django.setup()
from app.models import Thing  # safe now

Run the task through manage.py

A custom management command runs after Django is fully set up, so the registry is already populated.

Terminal
python manage.py seed_demo_data

How to prevent it

  • Never import models at the top of a standalone script before django.setup().
  • Move one-off tasks into management commands.
  • Defer ORM access until inside a function, not module import.

Frequently asked questions

What causes ""Apps aren't loaded yet""?
A script imports from app.models import Thing at module top level without configuring Django first, so the app registry has not been built.
How do I fix "Apps aren't loaded yet"?
Call django.setup() before importing models

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card