TypeError ForeignKey__init__ missing 1 required positional argument on_delete为什么
这个错误通常是由于在定义外键时没有指定 on_delete 参数引起的。on_delete 参数用于指定在关联对象被删除时如何处理本地对象。on_delete 参数是必需的,因为它是在 Django 2.0 版本中引入的。在之前的版本中,它默认为 CASCADE。因此,您需要在定义外键时指定 on_delete 参数。例如:
class MyModel(models.Model):
my_foreign_key = models.ForeignKey(OtherModel, on_delete=models.CASCADE)
原文地址: https://www.cveoy.top/t/topic/gU3L 著作权归作者所有。请勿转载和采集!