-2

I recently got a task to upgrade my whole Django project to newer version. Currently we are using python version = 2.7 and django version = 1.11.3

When I am upgrading the django version to 2.2.16 and python version to 3.7.12 Now I am getting error -

TypeError: init() missing 1 required positional argument: 'on_delete'

I want two suggestions first how can I add on_delete to all the models of all the apps in my whole project and secondly to which python and django version I should migrate my project to ?

It would be so helpful to me....Thank You in Advance.

  • Does this answer your question? [Getting TypeError: \_\_init\_\_() missing 1 required positional argument: 'on\_delete' when trying to add parent table after child table with entries](https://stackoverflow.com/questions/44026548/getting-typeerror-init-missing-1-required-positional-argument-on-delete) – Sumithran Jan 07 '22 at 10:19
  • @Sumithran No this does not answer because What I want is - Is there any better way to put on_delete on all the models for all the apps apart from doing it manually as the project is so vast that it is very hard to go and put on_delete for all the foreign keys in all the models. – Kritik Alawat Jan 07 '22 at 10:32

1 Answers1

0

Since Django 2.x all of your foreign keys must have an on_delete resolution. You can use models.DO_NOTHING, but most of the time this suggest some other flaw in the database.

Here's a link to the on_delete documentation and all available options.

Misho Janev
  • 512
  • 5
  • 13
  • This does not answer my question because What I want is - Is there any better way to put on_delete on all the models for all the apps apart from doing it manually as the project is so vast that it is very hard to go and put on_delete for all the foreign keys in all the models – Kritik Alawat Jan 07 '22 at 10:34
  • Except for writing a script that will generate a migration for you for every field that is foreign key and will alter that field to have an on_delete property I cannot think of a more scripted way. I do not believe this is natively supported. – Misho Janev Jan 07 '22 at 15:26