Python3 - Django2 - TypeError: __init__() missing 1 required positional argument: 'on_delete'

Python3 - Django2 - TypeError: __init__() missing 1 required positional argument: 'on_delete'

我最近将我的项目从 python2 迁移到 python3,它有数百个外键关系。

使用解决方案逐行添加 on_delete 参数是不可能的。解决此错误的替代方法是什么?

我试过编辑库,我可以在 init 函数中添加带有默认值的参数,但有时看起来不像是捕捉到它。

Using the solution to go line by line and add on_delete argument is not possible

任何体面的代码编辑器都应该使此操作相对容易,而且这仍然是漫长 运行 中唯一明智的解决方案。

与此同时,您可以 just monkeypatch models.ForeignKey.__init__ 而不是直接弄乱 Django 的源代码 - 只需确保在加载任何应用 models.py 之前应用您的 monkeypatch .但这必须被视为临时解决方法,而不是可行的解决方案。