#23728: sys.exit(1) from makemigrations if no changes found
-------------------------------------+-------------------------------------
Reporter: tim_heap | Owner: nobody
Type: New feature | Status: closed
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by mgeisler):
The work-around turned out to be easy! Drop this into a
`your_app/management/commands/checkmigrations.py` file:
{{{
from django.core.management.commands import makemigrations
class Command(makemigrations.Command):
help = 'Check that there are no outstanding migrations.'
def add_arguments(self, parser):
parser.add_argument('args', metavar='app_label', nargs='*',
help=('Specify the app label(s) to check '
'migrations for.'))
def handle(self, *args, **options):
options['dry_run'] = True
options['exit_code'] = True
try:
super().handle(*args, **options)
# The handle method doesn't call sys.exit when it is
# successful, so we do it here.
raise SystemExit(0)
except SystemExit as exc:
# Swap exit code 0 and 1.
if exc.code == 0:
if self.verbosity >= 1:
msg = ("Outstanding migrations detected, "
"please run makemigrations.")
self.stdout.write(self.style.ERROR(msg))
raise SystemExit(1)
if exc.code == 1:
raise SystemExit(0)
raise # Let other exit codes propagate unchanged.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23728#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.055fe2da55f234a5d295e7765f789b1c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.