tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
804 stars 90 forks source link

Model with multiple FKs to same table throws error or finds changes that aren't there #330

Open markmiscavage opened 3 months ago

markmiscavage commented 3 months ago

In aerich/migrate.py line 244 the list of dicts being diff'd aren't ordered so there are cases when the diff is finding changes only due to ordering.

Monkey Patch to fix:

`import operator

old_m2m_fields = sorted(old_m2m_fields, key=operator.itemgetter('name')) new_m2m_fields = sorted(new_m2m_fields, key=operator.itemgetter('name'))`