From df448bfd0259edb7df19c9c445ab4ee58624245d Mon Sep 17 00:00:00 2001 From: Junyoung Date: Mon, 1 Oct 2018 23:03:10 +0900 Subject: Fixed #29783 -- Added app label validation to showmigrations command. --- django/core/management/commands/showmigrations.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'django') diff --git a/django/core/management/commands/showmigrations.py b/django/core/management/commands/showmigrations.py index abac283160..4c86ba1a17 100644 --- a/django/core/management/commands/showmigrations.py +++ b/django/core/management/commands/showmigrations.py @@ -1,4 +1,7 @@ -from django.core.management.base import BaseCommand, CommandError +import sys + +from django.apps import apps +from django.core.management.base import BaseCommand from django.db import DEFAULT_DB_ALIAS, connections from django.db.migrations.loader import MigrationLoader @@ -45,12 +48,15 @@ class Command(BaseCommand): return self.show_list(connection, options['app_label']) def _validate_app_names(self, loader, app_names): - invalid_apps = [] + has_bad_names = False for app_name in app_names: - if app_name not in loader.migrated_apps: - invalid_apps.append(app_name) - if invalid_apps: - raise CommandError('No migrations present for: %s' % (', '.join(sorted(invalid_apps)))) + try: + apps.get_app_config(app_name) + except LookupError as err: + self.stderr.write(str(err)) + has_bad_names = True + if has_bad_names: + sys.exit(2) def show_list(self, connection, app_names=None): """ @@ -129,3 +135,5 @@ class Command(BaseCommand): self.stdout.write("[X] %s.%s%s" % (node.key[0], node.key[1], deps)) else: self.stdout.write("[ ] %s.%s%s" % (node.key[0], node.key[1], deps)) + if not plan: + self.stdout.write('(no migrations)', self.style.ERROR) -- cgit v1.3