Python TypeError: __init__() missing 1 required positional argument: ‘on_delete’

TypeError: __ init__() missing 1 required positional argument: ‘on_ Delete ‘solution

Error: typeerror: init() missing 1 required position argument: ‘on’ when executing Python manage.py makemigrations_ delete’

solutions:

when defining foreign keys, you need to add on_ delete=;
that is: contract = models. ForeignKey (contract, on)_ delete=models.CASCADE)

the reasons are as follows:

after Django is upgraded to 2.0, when tables are associated with each other, on must be written_ Delete parameter, otherwise an exception will be reported:
typeerror: init() missing 1 required position argument: ‘on’_ delete’

on_ Delete = none, # when deleting data in an associated table, the current table and its associated field behave
on_ Delete = models.cascade, # delete the associated data and delete the associated data
on_ delete=models.DO_ Noting, # delete associated data and do nothing
on_ Delete = models. Protect, # delete the associated data, causing the error protectederror
# models. ForeignKey (‘associated table ‘, on)_ delete=models.SET_ NULL, blank=True, null=True)
on_ delete=models.SET_ Null, # delete the associated data, and set the associated value to null (if FK field needs to be set to null, one-to-one is the same)
# models.foreignkey (‘association table ‘, on)_ delete=models.SET_ Default, default =’default ‘)
on_ delete=models.SET_ Default, # delete the associated data, and set the associated value as the default value (if FK field needs to set the default value, one-to-one is the same)
on_ Delete = models.set, # delete associated data,
A. set the associated value to the specified value, set: models.set (value)
B. set the associated value to the return value of executable object, set: models.set (executable object)

a

Because many to many (manytomanyfield) has no on_ Delete parameter, so the above is only for foreign key and one to one field

Similar Posts: