Weird ephemeral error for ManyToMany fields during Django migrations

青春壹個敷衍的年華 提交于 2019-12-11 17:14:39

问题


There's this weird error that my company has been facing since the last few months. We have a ton of models 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!