0

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.

Nayan Goenka
  • 85
  • 2
  • 11
  • 2
    related: https://stackoverflow.com/questions/57913061/how-to-automatically-update-foreignkeys-to-have-on-delete-models-protect/57913144#57913144 – Joy Dec 11 '19 at 11:30

1 Answers1

2

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.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
  • For now I've edited the source library meanwhile figuring out a regex to help with this. Its not going to be a simple regex. – Nayan Goenka Dec 12 '19 at 07:47