Django模型外键不创建反向关系 设置方法

related_name设置为+或者以+结尾即可

If you'd prefer Django not to create a backwards relation, set related_name to '+' or end it with '+'. For example, this will ensure that the User model won't have a backwards relation to this model:

user = models.ForeignKey(
    User,
    on_delete=models.CASCADE,
    related_name='+',)


猜你喜欢

转载自blog.51cto.com/wenguonideshou/2155082