django/django · error · ImproperlyConfigured

The MEDIA_ROOT and STATIC_ROOT settings must have different

Error message

The MEDIA_ROOT and STATIC_ROOT settings must have different values

What it means

Raised by check_settings() when both MEDIA_ROOT and STATIC_ROOT are set and equal. Sharing one directory would mix user-uploaded media with collected static files (which collectstatic may clear), causing data loss and ambiguous storage behavior, so Django forbids it.

Source

Thrown at django/contrib/staticfiles/utils.py:69

            "without having set the required STATIC_URL setting."
        )
    if settings.MEDIA_URL == base_url:
        raise ImproperlyConfigured(
            "The MEDIA_URL and STATIC_URL settings must have different values"
        )
    if (
        settings.DEBUG
        and settings.MEDIA_URL
        and settings.STATIC_URL
        and settings.MEDIA_URL.startswith(settings.STATIC_URL)
    ):
        raise ImproperlyConfigured(
            "runserver can't serve media if MEDIA_URL is within STATIC_URL."
        )
    if (settings.MEDIA_ROOT and settings.STATIC_ROOT) and (
        settings.MEDIA_ROOT == settings.STATIC_ROOT
    ):
        raise ImproperlyConfigured(
            "The MEDIA_ROOT and STATIC_ROOT settings must have different values"
        )

View on GitHub (pinned to b5388a3a80)

Solutions

  1. Set STATIC_ROOT and MEDIA_ROOT to different directories (e.g. BASE_DIR/'staticfiles' vs BASE_DIR/'media').
  2. If they share a parent, give each its own subdirectory so the path strings differ.

Example fix

# before
STATIC_ROOT = "/var/www/data"
MEDIA_ROOT = "/var/www/data"  # identical -> error

# after
STATIC_ROOT = "/var/www/static"
MEDIA_ROOT = "/var/www/media"
Defensive patterns

Strategy: validation

Validate before calling

from django.conf import settings

if settings.MEDIA_ROOT and settings.STATIC_ROOT and settings.MEDIA_ROOT == settings.STATIC_ROOT:
    raise SystemExit("MEDIA_ROOT must differ from STATIC_ROOT")

Try / catch

from django.core.exceptions import ImproperlyConfigured
from django.contrib.staticfiles.utils import check_settings

try:
    check_settings()
except ImproperlyConfigured:
    raise

Prevention

When it happens

Trigger: MEDIA_ROOT and STATIC_ROOT resolve to the same path string in settings. Fires during storage initialization / collectstatic.

Common situations: Pointing both at the same folder for convenience; a settings refactor that aliased them; deploying without separating the two trees.

Related errors


AI-assisted analysis of django/django@b5388a3a80 (2026-08-10). Data as JSON: /api/errors/61939bd0a2a8a7bc. Report an issue: GitHub.