Should we create an initial migration for the app?
(self, app_label)
| 25 | self.dry_run = dry_run |
| 26 | |
| 27 | def ask_initial(self, app_label): |
| 28 | """Should we create an initial migration for the app?""" |
| 29 | # If it was specified on the command line, definitely true |
| 30 | if app_label in self.specified_apps: |
| 31 | return True |
| 32 | # Otherwise, we look to see if it has a migrations module |
| 33 | # without any Python files in it, apart from __init__.py. |
| 34 | # Apps from the new app template will have these; the Python |
| 35 | # file check will ensure we skip South ones. |
| 36 | try: |
| 37 | app_config = apps.get_app_config(app_label) |
| 38 | except LookupError: # It's a fake app. |
| 39 | return self.defaults.get("ask_initial", False) |
| 40 | migrations_import_path, _ = MigrationLoader.migrations_module(app_config.label) |
| 41 | if migrations_import_path is None: |
| 42 | # It's an application with migrations disabled. |
| 43 | return self.defaults.get("ask_initial", False) |
| 44 | try: |
| 45 | migrations_module = importlib.import_module(migrations_import_path) |
| 46 | except ImportError: |
| 47 | return self.defaults.get("ask_initial", False) |
| 48 | else: |
| 49 | if getattr(migrations_module, "__file__", None): |
| 50 | filenames = os.listdir(os.path.dirname(migrations_module.__file__)) |
| 51 | elif hasattr(migrations_module, "__path__"): |
| 52 | if len(migrations_module.__path__) > 1: |
| 53 | return False |
| 54 | filenames = os.listdir(list(migrations_module.__path__)[0]) |
| 55 | return not any(x.endswith(".py") for x in filenames if x != "__init__.py") |
| 56 | |
| 57 | def ask_not_null_addition(self, field_name, model_name): |
| 58 | """Adding a NOT NULL field to a model.""" |