File "C:\Users\sungk\Git\django_website\blog\models.py", line 5, in <module> class Post(models.Model):
File "C:\Users\sungk\Git\django_website\blog\models.py", line 10, in Post author = models.ForeignKey(User, on_delete=True) File "C:\Users\sungk\Git\django_website\venv\lib\site-packages\django\db\models\fields\related.py", line 813, in __init__ raise TypeError('on_delete must be callable.') TypeError: on_delete must be callable.
{a1}可以而不是是{}。它应该是一个可调用的函数。通常它是作为described in the documentation的一个内置项。这可以是^{} 、^{} 、^{} 、^{} 、^{} 、^{} 或^{}
严格地说,您也可以使自己的可调用性,但这仅适用于您想要做比上面列出的更复杂的事情的情况
on_delete=…
指定在删除作为作者的User
对象的情况下,如何处理与相关的Post
。通过使用CASDCADE
,相关的Post
对象将被删除:相关问题 更多 >
编程相关推荐