diff options
| author | Gordon Pendleton <wgordonw1@gmail.com> | 2020-03-26 05:08:58 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-26 20:12:39 +0100 |
| commit | d0da2820cab495c35eac10680213f927be8b91b0 (patch) | |
| tree | 0f065f06f8c84994741acc57f0814fb8677f3cc0 /django/core | |
| parent | 421622548060499881df9966b7a352bce63901cd (diff) | |
Fixed #31402 -- Added migrate --check option.
Command exits with non-zero status if unapplied migrations exist.
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/commands/migrate.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 575ed47993..85e04b6fcc 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -1,3 +1,4 @@ +import sys import time from importlib import import_module @@ -62,6 +63,10 @@ class Command(BaseCommand): '--run-syncdb', action='store_true', help='Creates tables for apps without migrations.', ) + parser.add_argument( + '--check', action='store_true', dest='check_unapplied', + help='Exits with a non-zero status if unapplied migrations exist.', + ) @no_translations def handle(self, *args, **options): @@ -143,6 +148,7 @@ class Command(BaseCommand): targets = executor.loader.graph.leaf_nodes() plan = executor.migration_plan(targets) + exit_dry = plan and options['check_unapplied'] if options['plan']: self.stdout.write('Planned operations:', self.style.MIGRATE_LABEL) @@ -154,7 +160,11 @@ class Command(BaseCommand): message, is_error = self.describe_operation(operation, backwards) style = self.style.WARNING if is_error else None self.stdout.write(' ' + message, style) + if exit_dry: + sys.exit(1) return + if exit_dry: + sys.exit(1) # At this point, ignore run_syncdb if there aren't any apps to sync. run_syncdb = options['run_syncdb'] and executor.loader.unmigrated_apps |
