{"record":{"id":"3dc4f2d33d856291","repo":"django/django","slug":"you-must-supply-at-least-one-app-label-when-using","errorCode":null,"errorMessage":"You must supply at least one app label when using --empty.","messagePattern":"You must supply at least one app label when using --empty\\.","errorType":"console","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"django/core/management/commands/makemigrations.py","lineNumber":224,"sourceCode":"            )\n        else:\n            questioner = NonInteractiveMigrationQuestioner(\n                specified_apps=app_labels,\n                dry_run=self.dry_run,\n                verbosity=self.verbosity,\n                log=self.log,\n            )\n        # Set up autodetector\n        autodetector = self.autodetector(\n            loader.project_state(),\n            ProjectState.from_apps(apps),\n            questioner,\n        )\n\n        # If they want to make an empty migration, make one for each app\n        if self.empty:\n            if not app_labels:\n                raise CommandError(\n                    \"You must supply at least one app label when using --empty.\"\n                )\n            # Make a fake changes() result we can pass to arrange_for_graph\n            changes = {app: [Migration(\"custom\", app)] for app in app_labels}\n            changes = autodetector.arrange_for_graph(\n                changes=changes,\n                graph=loader.graph,\n                migration_name=self.migration_name,\n            )\n            self.write_migration_files(changes)\n            return\n\n        # Detect changes\n        changes = autodetector.changes(\n            graph=loader.graph,\n            trim_to_apps=app_labels or None,\n            convert_apps=app_labels or None,\n            migration_name=self.migration_name,","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/management/commands/makemigrations.py#L206-L242","documentation":"The --empty flag tells makemigrations to create a blank migration skeleton (no auto-detected operations), but the command needs to know which app to create it for. Without at least one positional app_label argument, there is no target directory (app/migrations/) to write the file into. The check at line 223 fires when `self.empty` is True and `app_labels` is empty.","triggerScenarios":"Running `python manage.py makemigrations --empty` with no app label arguments. Also via `call_command('makemigrations', empty=True)` with no positional args.","commonSituations":"Developer wants a hand-written data migration but forgets to specify the app, or assumes --empty applies to all apps.","solutions":["Add the app label: `python manage.py makemigrations --empty myapp`","Optionally combine with -n to name it: `python manage.py makemigrations --empty myapp -n custom_data`"],"exampleFix":"// before\npython manage.py makemigrations --empty\n// after\npython manage.py makemigrations --empty myapp -n custom_data","handlingStrategy":"validation","validationCode":"from django.core.management import call_command\n\napp_labels = [\"myapp\"]  # must be non-empty when empty=True\nif not app_labels:\n    raise ValueError(\"At least one app label is required with --empty\")\ncall_command(\"makemigrations\", *app_labels, empty=True)","typeGuard":"def has_app_labels(app_labels) -> bool:\n    \"\"\"True if at least one app label is provided for --empty mode.\"\"\"\n    return bool(app_labels) and all(isinstance(a, str) and a for a in app_labels)","tryCatchPattern":"from django.core.management import call_command\nfrom django.core.management.base import CommandError\n\ntry:\n    call_command(\"makemigrations\", empty=True)\nexcept CommandError as e:\n    if \"supply at least one app label\" in str(e):\n        call_command(\"makemigrations\", \"myapp\", empty=True)\n    else:\n        raise","preventionTips":["Always pair --empty with an explicit app label argument","Use shell completion or aliases that include the app label by default"],"tags":["django","migrations","cli-args","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}