2👍
✅
Dictionaries have an arbitrary order, so your tuple has an arbitrary order as well. Especially on Python 3.3+ the order is likely to change because it uses a random hash seed. As such, the order of the tuple is different as well, and tuples with the same items but a different order don’t compare equal. Django detects this change and creates a new migration.
To fix this, simply sort the keys before constructing the tuple:
@deconstructible
class EnumType(object):
@classmethod
def choices(cls):
attrs = [i for i in cls.__dict__.keys() if i[:1] != '_' and i.isupper()]
return tuple((cls.__dict__[attr], cls.__dict__[attr]) for attr in sorted(attrs))
def __eq__(self, other):
return self.choices() == other.choices()
👤knbk
Source:stackexchange.com