[Solved] Pycharm Error: TypeError: init() missing 1 required positional argument: ‘on_delete’

TypeError: init() missing 1 required positional argument: ‘on_ delete’

After Django 2.0, you need to add on when defining foreign keys and one-to-one relationships_delete option. This parameter is used to avoid data inconsistency between the two tables, otherwise an error will be reported:

Original: user=models.OneToOneField(User)
Now: user=models.OneToOneField(User,on_delete=models.CASCADE) The original (models.CASCADE) exists by default

on_delete includes cascade, protect and set_NULL, SET_Default and set() are five selectable values

CASCADEļ¼šThis value is set to cascade delete. PROTECT: This value is set to report an integrity error. SET_NULL: This value is set to set the foreign key to null, provided it is allowed to be null. SET_DEFAULT: This value is set to set as the default value of the foreign key. SET(): This value is set to call the outside value, which can be a function. CASCADE is used in general.

After Django 2.0, the editing mode in include will be changed

Change: url(r'^student/', include('student.ursl', namespace="student"))
to:url(r'^student/', include(('student.ursl',"student"), namespace="student"))

Similar Posts: