summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJunyoung <cupjoo@naver.com>2018-10-01 23:03:10 +0900
committerTim Graham <timograham@gmail.com>2018-10-30 19:29:00 -0400
commitdf448bfd0259edb7df19c9c445ab4ee58624245d (patch)
treee4380afab5ea2fb1161302318855ab1783fe223d /django
parent817c6cdf0e2a72362045ca503af01830df9b9d36 (diff)
Fixed #29783 -- Added app label validation to showmigrations command.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/showmigrations.py20
1 files changed, 14 insertions, 6 deletions
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)