From b25c7671bb7aa45695f69a218c980bba3a5ac4a7 Mon Sep 17 00:00:00 2001 From: "artem.ulchenko" Date: Thu, 18 Jan 2024 10:50:31 +0300 Subject: [PATCH] try to fix "Add ManyToManyField will break migrate #150" issues --- aerich/migrate.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aerich/migrate.py b/aerich/migrate.py index bedea8d..32cad7f 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -258,7 +258,13 @@ class Migrate: for action, option, change in diff(old_m2m_fields, new_m2m_fields): if change[0][0] == "db_constraint": continue - table = change[0][1].get("through") + if isinstance(change[0][1], str): + for new_m2m_field in new_m2m_fields: + if new_m2m_field["name"] == change[0][1]: + table = new_m2m_field.get("through") + break + else: + table = change[0][1].get("through") if action == "add": add = False if upgrade and table not in cls._upgrade_m2m: