简体   繁体   中英

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

I have recently migrated my project from python2 to python3 and it has hundreds of ForeignKey relations.

Using the solution to go line by line and add on_delete argument is not possible. What can be the alternate way of resolving this error?

I have tried editing the library where I can add the argument in the init function with a default value but it doesn't look like catching it sometimes.

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

Any decent code editor should make this operation relatively easy, and that's still the only sane solution in the long run anyway.

In the meantime, instead of messing with Django's source code directly, you can just monkeypatch models.ForeignKey.__init__ - just make sure your monkeypatch is applied before any of your apps models.py are loaded. But this has to be seen as a temporary workaround, not as a viable solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM