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:
- Python TypeError: __init__() missing 1 required positional argument: ‘on_delete’
- [How to Solve]error: invalid array assignment
- python Warning: OverflowError: Python int too large to convert to C long
- How to Solve Django Error: No such column: xxx
- With check option in SQL
- [Solved] MYSQL Error: Cannot delete or update a parent row: a foreign key constraint fails
- How to Solve Python TypeError: ‘module’ object is not callable
- [Solved] Hive Update and Delete Error: Attempt to do update or delete using transaction manager
- MySQL error message: subquery returns more than 1 row and its solution
- [design and development] Python learning notes – Super () argument 1 must be type, not classobj