1. 程式人生 > >Django2.0之後使用外來鍵時遇到 __init__() missing 1 required positional argument: 'on_delete' __init__() missing 1 required positional argument: 'on_

Django2.0之後使用外來鍵時遇到 __init__() missing 1 required positional argument: 'on_delete' __init__() missing 1 required positional argument: 'on_

1.Django2.0之後使用外來鍵時遇到

__init__() missing 1 required positional argument: 'on_delete'

需要在外來鍵建立時給on_delete引數賦值。models.CASCADE是老版本的預設值。

publish = models.ForeignKey("Publish", on_delete=models.CASCADE)