From beefac8aaeed0bd8c66e8c7fcbfae1c0f8e01f85 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 21 Aug 2013 22:27:46 +0100 Subject: [PATCH] Only create the migration directory once per app --- django/core/management/commands/makemigrations.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 9f0690b483..d802e2924a 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -61,6 +61,7 @@ class Command(BaseCommand): self.stdout.write("No changes detected") return + directory_created = {} for app_label, migrations in changes.items(): self.stdout.write(self.style.MIGRATE_HEADING("Migrations for '%s':" % app_label) + "\n") for migration in migrations: @@ -71,10 +72,13 @@ class Command(BaseCommand): self.stdout.write(" - %s\n" % operation.describe()) # Write it migrations_directory = os.path.dirname(writer.path) - 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() + 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 with open(writer.path, "w") as fh: fh.write(writer.as_string())