Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Only create the migration directory once per app

  • Loading branch information...
commit beefac8aaeed0bd8c66e8c7fcbfae1c0f8e01f85 1 parent 2d90392
Andrew Godwin authored August 21, 2013
14  django/core/management/commands/makemigrations.py
@@ -61,6 +61,7 @@ def handle(self, *app_labels, **options):
61 61
                 self.stdout.write("No changes detected")
62 62
             return
63 63
 
  64
+        directory_created = {}
64 65
         for app_label, migrations in changes.items():
65 66
             self.stdout.write(self.style.MIGRATE_HEADING("Migrations for '%s':" % app_label) + "\n")
66 67
             for migration in migrations:
@@ -71,10 +72,13 @@ def handle(self, *app_labels, **options):
71 72
                     self.stdout.write("    - %s\n" % operation.describe())
72 73
                 # Write it
73 74
                 migrations_directory = os.path.dirname(writer.path)
74  
-                if not os.path.isdir(migrations_directory):
75  
-                    os.mkdir(migrations_directory)
76  
-                init_path = os.path.join(migrations_directory, "__init__.py")
77  
-                if not os.path.isfile(init_path):
78  
-                    open(init_path, "w").close()
  75
+                if not directory_created.get(app_label, False):
  76
+                    if not os.path.isdir(migrations_directory):
  77
+                        os.mkdir(migrations_directory)
  78
+                    init_path = os.path.join(migrations_directory, "__init__.py")
  79
+                    if not os.path.isfile(init_path):
  80
+                        open(init_path, "w").close()
  81
+                    # We just do this once per app
  82
+                    directory_created[app_label] = True
79 83
                 with open(writer.path, "w") as fh:
80 84
                     fh.write(writer.as_string())

0 notes on commit beefac8

Please sign in to comment.
Something went wrong with that request. Please try again.