其他分享
首页 > 其他分享> > TypeError: __init__() missing 1 required positional argument: 'on_delete'

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

作者:互联网

class HeroInfo(models.Model):
    # 英雄名
    hname = models.CharField(max_length=20)
    # 性别
    hgender = models.BooleanField(default=False)
    # 备注
    hcomment = models.CharField(max_length=200)
    # 外键
    hbook = models.ForeignKey('BookInfo')
    # 删除标记
    isDelete = models.BooleanField(default=False)

创建迁移文件时报错:

报错环境 python=3.6,django=2.2,PyMySQL=0.9.3

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

原因:

django2.0之后定义外键时需指定'on_delete'参数值。

详见django官方文档:https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.ForeignKey

 

标签:__,TypeError,missing,models,ForeignKey,argument,django,delete
来源: https://www.cnblogs.com/AngelLoveRZZZ/p/10858942.html