{"record":{"id":"0c9b53cf0fedc3b4","repo":"django/django","slug":"r-declares-more-than-one-default-appconfig-s","errorCode":null,"errorMessage":"%r declares more than one default AppConfig: %s.","messagePattern":"%r declares more than one default AppConfig: (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"django/apps/config.py","lineNumber":147,"sourceCode":"                    if (\n                        issubclass(candidate, cls)\n                        and candidate is not cls\n                        and getattr(candidate, \"default\", True)\n                    )\n                ]\n                if len(app_configs) == 1:\n                    app_config_class = app_configs[0][1]\n                else:\n                    # Check if there's exactly one AppConfig subclass,\n                    # among those that explicitly define default = True.\n                    app_configs = [\n                        (name, candidate)\n                        for name, candidate in app_configs\n                        if getattr(candidate, \"default\", False)\n                    ]\n                    if len(app_configs) > 1:\n                        candidates = [repr(name) for name, _ in app_configs]\n                        raise RuntimeError(\n                            \"%r declares more than one default AppConfig: \"\n                            \"%s.\" % (mod_path, \", \".join(candidates))\n                        )\n                    elif len(app_configs) == 1:\n                        app_config_class = app_configs[0][1]\n\n            # Use the default app config class if we didn't find anything.\n            if app_config_class is None:\n                app_config_class = cls\n                app_name = entry\n\n        # If import_string succeeds, entry is an app config class.\n        if app_config_class is None:\n            try:\n                app_config_class = import_string(entry)\n            except Exception:\n                pass\n        # If both import_module and import_string failed, it means that entry","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/apps/config.py#L129-L165","documentation":"Raised as RuntimeError inside AppConfig.create when an app's apps.py module defines more than one AppConfig subclass with the class attribute `default = True`. Django uses default=True to disambiguate when multiple AppConfig subclasses exist; having two is contradictory.","triggerScenarios":"module_has_submodule finds apps.py, more than one AppConfig subclass passes the default filter, then re-filtering by `default=True` (config.py:140-144) yields >1 candidate. Common after copy-paste of an AppConfig block.","commonSituations":"Refactoring where a developer adds a new AppConfig, marks it default=True but forgets to remove default=True from the old one; merging two app configs from different branches.","solutions":["Inspect the named candidates in the error message and set `default = True` on exactly one of them (or none, if you reference the class explicitly in INSTALLED_APPS).","Reference the desired AppConfig explicitly in INSTALLED_APPS via 'myapp.apps.MyAppConfig' and remove all default=True markers."],"exampleFix":"# before — myapp/apps.py\nclass FooConfig(AppConfig):\n    name = 'myapp'\n    default = True\nclass BarConfig(AppConfig):\n    name = 'myapp'\n    default = True   # second default -> RuntimeError\n\n# after — keep a single default\nclass FooConfig(AppConfig):\n    name = 'myapp'\n    default = True\nclass BarConfig(AppConfig):\n    name = 'myapp'\n    # default omitted (defaults to True; but only Foo is explicitly default=True -> chosen)","handlingStrategy":"validation","validationCode":"import inspect\nfrom django.apps import AppConfig\nmod = import_module('myapp.apps')\ndefaults = [n for n, c in inspect.getmembers(mod, inspect.isclass)\n            if issubclass(c, AppConfig) and c is not AppConfig and getattr(c, 'default', False)]\nif len(defaults) > 1:\n    raise ValueError(f'Multiple default AppConfigs in myapp.apps: {defaults}')","typeGuard":"import inspect\nfrom django.apps import AppConfig\n\ndef has_single_default_appconfig(module) -> bool:\n    defaults = [c for _, c in inspect.getmembers(module, inspect.isclass)\n                if issubclass(c, AppConfig) and c is not AppConfig and getattr(c, 'default', False)]\n    return len(defaults) <= 1","tryCatchPattern":"try:\n    AppConfig.create('myapp')\nexcept RuntimeError as e:\n    if 'more than one default AppConfig' in str(e):\n        # reference one AppConfig explicitly in INSTALLED_APPS\n        raise SystemExit('Set INSTALLED_APPS=[\\'myapp.apps.MyAppConfig\\'] and clear default flags')\n    raise","preventionTips":["When adding a new AppConfig, audit existing apps.py for stale default=True flags.","Reference AppConfigs explicitly by dotted path in INSTALLED_APPS to avoid relying on default auto-discovery.","Code review should reject PRs introducing a second default=True in one apps.py."],"tags":["django","apps","appconfig","default-multiple","installed-apps"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}