(self, *app_labels, **options)
| 104 | |
| 105 | @no_translations |
| 106 | def handle(self, *app_labels, **options): |
| 107 | self.written_files = [] |
| 108 | self.verbosity = options["verbosity"] |
| 109 | self.interactive = options["interactive"] |
| 110 | self.dry_run = options["dry_run"] |
| 111 | self.merge = options["merge"] |
| 112 | self.empty = options["empty"] |
| 113 | self.migration_name = options["name"] |
| 114 | if self.migration_name and not self.migration_name.isidentifier(): |
| 115 | raise CommandError("The migration name must be a valid Python identifier.") |
| 116 | self.include_header = options["include_header"] |
| 117 | check_changes = options["check_changes"] |
| 118 | if check_changes: |
| 119 | self.dry_run = True |
| 120 | self.scriptable = options["scriptable"] |
| 121 | self.update = options["update"] |
| 122 | # If logs and prompts are diverted to stderr, remove the ERROR style. |
| 123 | if self.scriptable: |
| 124 | self.stderr.style_func = None |
| 125 | |
| 126 | # Make sure the app they asked for exists |
| 127 | app_labels = set(app_labels) |
| 128 | has_bad_labels = False |
| 129 | for app_label in app_labels: |
| 130 | try: |
| 131 | apps.get_app_config(app_label) |
| 132 | except LookupError as err: |
| 133 | self.stderr.write(str(err)) |
| 134 | has_bad_labels = True |
| 135 | if has_bad_labels: |
| 136 | sys.exit(2) |
| 137 | |
| 138 | # Load the current graph state. Pass in None for the connection so |
| 139 | # the loader doesn't try to resolve replaced migrations from DB. |
| 140 | loader = MigrationLoader(None, ignore_no_migrations=True) |
| 141 | |
| 142 | # Raise an error if any migrations are applied before their |
| 143 | # dependencies. |
| 144 | consistency_check_labels = {config.label for config in apps.get_app_configs()} |
| 145 | # Non-default databases are only checked if database routers used. |
| 146 | aliases_to_check = ( |
| 147 | connections if settings.DATABASE_ROUTERS else [DEFAULT_DB_ALIAS] |
| 148 | ) |
| 149 | for alias in sorted(aliases_to_check): |
| 150 | connection = connections[alias] |
| 151 | if connection.settings_dict["ENGINE"] != "django.db.backends.dummy" and any( |
| 152 | # At least one model must be migrated to the database. |
| 153 | router.allow_migrate( |
| 154 | connection.alias, app_label, model_name=model._meta.object_name |
| 155 | ) |
| 156 | for app_label in consistency_check_labels |
| 157 | for model in apps.get_app_config(app_label).get_models() |
| 158 | ): |
| 159 | try: |
| 160 | loader.check_consistent_history(connection) |
| 161 | except OperationalError as error: |
| 162 | warnings.warn( |
| 163 | "Got an error checking a consistent migration history " |
nothing calls this directly
no test coverage detected