Created
July 28, 2018 17:19
-
-
Save florimondmanca/53c6f3338aece50e0c4c3681bf21f3da to your computer and use it in GitHub Desktop.
Script to run a stand-alone equivalent of Django's `manage.py makemigrations`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Script to run a stand-alone equivalent of Django's `makemigrations`.""" | |
import sys | |
import django | |
from django.conf import settings | |
from django.core.management import call_command | |
def makemigrations(app_name: str): | |
"""Make migrations for the given app.""" | |
DJANGO_SETTINGS = { | |
'INSTALLED_APPS': (app_name,) | |
} | |
settings.configure(**DJANGO_SETTINGS) | |
django.setup() | |
call_command('makemigrations', app_name) | |
if __name__ == '__main__': | |
try: | |
app_name = sys.argv[1] | |
except IndexError: | |
sys.stderr.write('Usage: python makemigrations.py APP_NAME\n') | |
sys.exit(1) | |
else: | |
makemigrations(app_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment