summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-12-04 13:55:20 +0000
committerAndrew Godwin <andrew@aeracode.org>2013-12-04 13:55:20 +0000
commitab587fa51a3be3ffc6f011189c0abab32dec6155 (patch)
tree67aa0e010bded695dc5b6ee0340c3d8cc922c37f
parent1d20e6df9553346c79edd92e6e8934e9c5c4aa2c (diff)
Add --dry-run option to makemigrations
-rw-r--r--django/core/management/commands/makemigrations.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index 1079b4269c..bb07160bb6 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -14,17 +14,18 @@ from django.db.models.loading import cache
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
- make_option('--empty', action='store_true', dest='empty', default=False,
- help='Make a blank migration.'),
+ make_option('--dry-run', action='store_true', dest='dry_run', default=False,
+ help="Just show what migrations would be made; don't actually write them."),
)
help = "Creates new migration(s) for apps."
- usage_str = "Usage: ./manage.py makemigrations [--empty] [app [app ...]]"
+ usage_str = "Usage: ./manage.py makemigrations [--dry-run] [app [app ...]]"
def handle(self, *app_labels, **options):
self.verbosity = int(options.get('verbosity'))
self.interactive = options.get('interactive')
+ self.dry_run = options.get('dry_run', False)
# Make sure the app they asked for exists
app_labels = set(app_labels)
@@ -73,15 +74,16 @@ class Command(BaseCommand):
for operation in migration.operations:
self.stdout.write(" - %s\n" % operation.describe())
# Write it
- migrations_directory = os.path.dirname(writer.path)
- if not directory_created.get(app_label, False):
- if not os.path.isdir(migrations_directory):
- os.mkdir(migrations_directory)
- init_path = os.path.join(migrations_directory, "__init__.py")
- if not os.path.isfile(init_path):
- open(init_path, "w").close()
- # We just do this once per app
- directory_created[app_label] = True
- migration_string = writer.as_string()
- with open(writer.path, "wb") as fh:
- fh.write(migration_string)
+ if not self.dry_run:
+ migrations_directory = os.path.dirname(writer.path)
+ if not directory_created.get(app_label, False):
+ if not os.path.isdir(migrations_directory):
+ os.mkdir(migrations_directory)
+ init_path = os.path.join(migrations_directory, "__init__.py")
+ if not os.path.isfile(init_path):
+ open(init_path, "w").close()
+ # We just do this once per app
+ directory_created[app_label] = True
+ migration_string = writer.as_string()
+ with open(writer.path, "wb") as fh:
+ fh.write(migration_string)