diff options
| author | Moayad Mardini <moayad.m@gmail.com> | 2014-05-30 01:23:09 +0300 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-05-29 15:39:02 -0700 |
| commit | e4eae5df0ec222fa13d6bac226b3b10c75f3d40d (patch) | |
| tree | d8d43c9cace09fc7b5cead6299e8a90301a11c32 /django | |
| parent | 4956e182ac207437eaf182f076de6717ee00843c (diff) | |
[1.7.x] Fixed #22682 -- `makemigrations` will create `MIGRATION_MODULES` package
`makemigrations` will automatically create the package specified
in `MIGRATION_MODULES` if it doesn't already exist.
Thanks ovidiuc4 for the report.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/writer.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index c8a3a6cf76..f73c4b78a0 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -6,6 +6,7 @@ import decimal import collections from importlib import import_module import os +import sys import types from django.apps import apps @@ -158,7 +159,18 @@ class MigrationWriter(object): if '%s.%s' % (app_config.name, migrations_package_basename) == migrations_package_name: basedir = os.path.join(app_config.path, migrations_package_basename) else: - raise ImportError("Cannot open migrations module %s for app %s" % (migrations_package_name, self.migration.app_label)) + # In case of using MIGRATION_MODULES setting and the custom + # package doesn't exist, create one. + package_dirs = migrations_package_name.split(".") + create_path = os.path.join(sys.path[0], *package_dirs) + if not os.path.isdir(create_path): + os.makedirs(create_path) + for i in range(1, len(package_dirs) + 1): + init_dir = os.path.join(sys.path[0], *package_dirs[:i]) + init_path = os.path.join(init_dir, "__init__.py") + if not os.path.isfile(init_path): + open(init_path, "w").close() + return os.path.join(create_path, self.filename) return os.path.join(basedir, self.filename) @classmethod |
