{"record":{"id":"61939bd0a2a8a7bc","repo":"django/django","slug":"the-media-root-and-static-root-settings-must-have","errorCode":null,"errorMessage":"The MEDIA_ROOT and STATIC_ROOT settings must have different values","messagePattern":"The MEDIA_ROOT and STATIC_ROOT settings must have different values","errorType":"validation","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"error","filePath":"django/contrib/staticfiles/utils.py","lineNumber":69,"sourceCode":"            \"without having set the required STATIC_URL setting.\"\n        )\n    if settings.MEDIA_URL == base_url:\n        raise ImproperlyConfigured(\n            \"The MEDIA_URL and STATIC_URL settings must have different values\"\n        )\n    if (\n        settings.DEBUG\n        and settings.MEDIA_URL\n        and settings.STATIC_URL\n        and settings.MEDIA_URL.startswith(settings.STATIC_URL)\n    ):\n        raise ImproperlyConfigured(\n            \"runserver can't serve media if MEDIA_URL is within STATIC_URL.\"\n        )\n    if (settings.MEDIA_ROOT and settings.STATIC_ROOT) and (\n        settings.MEDIA_ROOT == settings.STATIC_ROOT\n    ):\n        raise ImproperlyConfigured(\n            \"The MEDIA_ROOT and STATIC_ROOT settings must have different values\"\n        )\n","sourceCodeStart":51,"sourceCodeEnd":72,"githubUrl":"https://github.com/django/django/blob/b5388a3a80cafcce2e34196d8e81cf5b48eb33bb/django/contrib/staticfiles/utils.py#L51-L72","documentation":"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.","triggerScenarios":"MEDIA_ROOT and STATIC_ROOT resolve to the same path string in settings. Fires during storage initialization / collectstatic.","commonSituations":"Pointing both at the same folder for convenience; a settings refactor that aliased them; deploying without separating the two trees.","solutions":["Set STATIC_ROOT and MEDIA_ROOT to different directories (e.g. BASE_DIR/'staticfiles' vs BASE_DIR/'media').","If they share a parent, give each its own subdirectory so the path strings differ."],"exampleFix":"# before\nSTATIC_ROOT = \"/var/www/data\"\nMEDIA_ROOT = \"/var/www/data\"  # identical -> error\n\n# after\nSTATIC_ROOT = \"/var/www/static\"\nMEDIA_ROOT = \"/var/www/media\"","handlingStrategy":"validation","validationCode":"from django.conf import settings\n\nif settings.MEDIA_ROOT and settings.STATIC_ROOT and settings.MEDIA_ROOT == settings.STATIC_ROOT:\n    raise SystemExit(\"MEDIA_ROOT must differ from STATIC_ROOT\")","typeGuard":null,"tryCatchPattern":"from django.core.exceptions import ImproperlyConfigured\nfrom django.contrib.staticfiles.utils import check_settings\n\ntry:\n    check_settings()\nexcept ImproperlyConfigured:\n    raise","preventionTips":["Use separate directories for collected static files and user uploads.","Compare settings.MEDIA_ROOT and settings.STATIC_ROOT in a deploy self-check.","Document the data-loss risk of sharing the directory (collectstatic --clear)."],"tags":["staticfiles","configuration","static-root","media-root","improperly-configured"],"backgroundTag":null,"analyzedSha":"b5388a3a80cafcce2e34196d8e81cf5b48eb33bb","analyzedAt":"2026-08-10T17:37:52.993Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}