summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Heap <tim@timheap.me>2014-11-11 15:41:55 +1100
committerTim Graham <timograham@gmail.com>2014-11-28 07:48:39 -0500
commitdeb607648ed7d484a90474b6da48642b4f39bca7 (patch)
treef9728781a87ed9b8f708aa9803c19c3607c7e0e0 /django
parentab89414f40db1598364a7fe4cfac1766cacd2668 (diff)
Fixed #23728 -- Added the --exit option to makemigrations.
If no changes that need migrations are found, `makemigrations --exit` exits with error code 1.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/makemigrations.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index bc684f42b7..bc78ff5f84 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -30,6 +30,8 @@ class Command(BaseCommand):
help='Tells Django to NOT prompt the user for input of any kind.')
parser.add_argument('-n', '--name', action='store', dest='name', default=None,
help="Use this name for migration file(s).")
+ parser.add_argument('-e', '--exit', action='store_true', dest='exit_code', default=False,
+ help='Exit with error code 1 if no changes needing migrations are found.')
def handle(self, *app_labels, **options):
@@ -39,6 +41,7 @@ class Command(BaseCommand):
self.merge = options.get('merge', False)
self.empty = options.get('empty', False)
self.migration_name = options.get('name', None)
+ self.exit_code = options.get('exit_code', False)
# Make sure the app they asked for exists
app_labels = set(app_labels)
@@ -120,15 +123,20 @@ class Command(BaseCommand):
migration_name=self.migration_name,
)
- # No changes? Tell them.
- if not changes and self.verbosity >= 1:
- if len(app_labels) == 1:
- self.stdout.write("No changes detected in app '%s'" % app_labels.pop())
- elif len(app_labels) > 1:
- self.stdout.write("No changes detected in apps '%s'" % ("', '".join(app_labels)))
+ if not changes:
+ # No changes? Tell them.
+ if self.verbosity >= 1:
+ if len(app_labels) == 1:
+ self.stdout.write("No changes detected in app '%s'" % app_labels.pop())
+ elif len(app_labels) > 1:
+ self.stdout.write("No changes detected in apps '%s'" % ("', '".join(app_labels)))
+ else:
+ self.stdout.write("No changes detected")
+
+ if self.exit_code:
+ sys.exit(1)
else:
- self.stdout.write("No changes detected")
- return
+ return
self.write_migration_files(changes)