在文档中,它仅指定与外键关系一起使用的 on_delete
属性,以指定删除相关外键对象时的行为。您可以将相同的属性与 OneToOneField
一起使用吗?
最佳答案
来自docs :
OneToOneField
accepts all of the extra arguments accepted byForeignKey
.
所以,是的,on_delete
应该按您的预期工作。
(如果您好奇,可以查看 the implementation 。您会发现 OneToOneField
是 ForeignKey
的一个小子类,它基本上只是强制 唯一
为True
。)
关于python - Django - 您可以在 OnetoOneField 上使用 on_delete 属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27679870/