问题
There's this weird error that my company has been facing since the last few months. We have a ton of model
s in our code and a lot of them have ManyToMany
fields in them. For ex -
class TypeMapping(models.Model):
name = models.TextField(null=True, blank=True)
from_config_type = models.ManyToManyField(Type, blank=True, related_name="from_config_type")
to_config_type = models.ManyToManyField(Type, blank=True, related_name="to_config_type")
Sometimes, and only sometimes, after a deployment, we start getting errors like these
Error :- Cannot resolve keyword 'to_config_type' into field. Choices are: <a long list of choices which does include 'to_config_type'.
We use AWS and this error only crops up sometimes, and that too, only on one server instance we have.
I know that related_name
and field_name
should not be the same, but that's for abstract base classes. The above model isn't one.
I've racked my head at this and so have my teammates but we couldn't land on anything.
Can anyone help us on this?
Sample query -
sample_type = Type.objects.get(pk=322)
TypeMapping.objects.filter(from_config_type=sample_type)
Thanks!
来源:https://stackoverflow.com/questions/57741495/weird-ephemeral-error-for-manytomany-fields-during-django-migrations