python – Getting TypeError: __init__() missing 1 required positional argument: on_delete when trying to add parent table after child table with entries
python – Getting TypeError: __init__() missing 1 required positional argument: on_delete when trying to add parent table after child table with entries
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
, check the documentation for more details:
https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey
EDIT:
As you stated in your comment, that you dont have any special requirements for on_delete
, you could use the option DO_NOTHING
:
# ...
on_delete=models.DO_NOTHING,
# ...
Since Django 2.x, on_delete
is required.
Deprecated since version 1.9: on_delete will become a required
argument in Django 2.0. In older versions it defaults to CASCADE.
python – Getting TypeError: __init__() missing 1 required positional argument: on_delete when trying to add parent table after child table with entries
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.