Django:on_delete=models.SET.NULL给出错误



为什么我的模型类中的属性

class Tour_Cart(models.Model):
tours=models.ForeignKey(Tours,on_delete=models.SET_NULL,blank=True,null=True)

抛出错误:

属性错误:"function"对象没有属性"NULL">

为什么会这样?

有什么需要帮忙的吗?

我想你刚刚错过了SET.NULL,它应该是on_delete=models.SET_NULL

为什么不使用on_delete=models.CASCADE

此外,您的类声明中缺少(models.Model)

最新更新