Skip to content
Latchkey

Django "Requested setting ... but settings are not configured" in CI

Django tried to read a setting before it knew which settings module to load. On a runner this means DJANGO_SETTINGS_MODULE was never exported and no settings.configure() ran, so any access to settings.X raises before your code starts.

What this error means

A management command, migration, or test run stops with "ImproperlyConfigured: Requested setting X, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."

Django
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS,
but settings are not configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Common causes

DJANGO_SETTINGS_MODULE is not exported to the step

Your shell locally sets it (or manage.py defaults it), but the CI step runs a bare python or pytest with no environment variable, so Django has no settings module to import.

A script imports Django models before setup

A helper script touches ORM models or django.conf.settings at import time without calling django.setup(), so the settings access fires before configuration.

How to fix it

Export DJANGO_SETTINGS_MODULE in the job

  1. Point it at your CI settings module (or the default one).
  2. Set it at the job or step level so every command inherits it.
  3. Prefer manage.py, which sets a default, over bare python for one-off commands.
.github/workflows/ci.yml
env:
  DJANGO_SETTINGS_MODULE: myproject.settings.ci

Call django.setup() in standalone scripts

A script run outside manage.py must configure Django before touching settings or models.

scripts/seed.py
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings.ci")
django.setup()

How to prevent it

  • Set DJANGO_SETTINGS_MODULE once at the job level, not per command.
  • Run management tasks through manage.py so a default module applies.
  • Never access django.conf.settings at module import time in scripts.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →