close

[Solved] Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Getting TypeError: init() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Getting TypeError: init() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries Error Occurs?

Today I get the following error Getting TypeError: init() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries in python.

How To Solve Getting TypeError: init() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries Error ?

  1. How To Solve Getting TypeError: init() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries Error ?

    To Solve Getting TypeError: init() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries Error As you stated in your comment, that you don't have any special requirements for on_delete, you could use the option DO_NOTHING:

  2. Getting TypeError: init() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries

    To Solve Getting TypeError: init() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries Error As you stated in your comment, that you don't have any special requirements for on_delete, you could use the option DO_NOTHING:

Solution 1

You can change the property categorie of the class Article like this:

categorie = models.ForeignKey(
    'Categorie',
    on_delete=models.CASCADE,
)

and the error should disappear.

Eventually you might need another option for on_delete

EDIT:

As you stated in your comment, that you don’t have any special requirements for on_delete, you could use the option DO_NOTHING:

# ...
on_delete=models.DO_NOTHING,
# ...

Solution 2

From Django 2.0 on_delete is required:

user = models.OneToOneField(User, on_delete=models.CASCADE)

It will delete the child table data if the User is deleted. For more details check the Django documentation.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read