diff --git a/aerich/migrate.py b/aerich/migrate.py index edca5de..7abb4a9 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -7,7 +7,7 @@ import asyncclick as click from dictdiffer import diff -from tortoise import BaseDBAsyncClient, Model, Tortoise +from tortoise import BaseDBAsyncClient, ConfigurationError, Model, Tortoise from tortoise.exceptions import OperationalError from tortoise.indexes import Index @@ -248,6 +248,8 @@ def _handle_m2m_fields( if new_m2m_field["name"] == new_value: table = cast(str, new_m2m_field.get("through")) break + else: + raise ConfigurationError(f"{new_value!r} not found in new_m2m_fields!") else: table = new_value.get("through") if action == "add": @@ -405,7 +407,7 @@ def diff_models( if new_model_str not in models_with_rename_field: if models_with_rename_field: # When there are multi rename fields with different models, - # print a empty line to warn that is another model + # print an empty line to warn that is another model prefix = "\n" + prefix models_with_rename_field.add(new_model_str) is_rename = click.prompt( @@ -603,7 +605,7 @@ def _resolve_fk_fields_name(cls, model: Type[Model], fields_name: Iterable[str]) try: field = model._meta.fields_map[field_name] except KeyError: - # field dropped or to be add + # field dropped or to be added pass else: if field.source_field: @@ -695,7 +697,7 @@ def _add_fk( @classmethod def _merge_operators(cls) -> None: """ - fk/m2m/index must be last when add,first when drop + fk/m2m/index must be last when add, first when drop :return: """ for _upgrade_fk_m2m_operator in cls._upgrade_fk_m2m_index_operators: