首页 > 其他 > 详细

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

时间:2019-05-13 21:45:51      阅读:830      评论:0      收藏:0      [点我收藏+]
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

 PS:

django2.1以后不再支持mysql5.5,python manage.py migrate时会报错:

 raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in
 your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near (6) NOT NULL)
at line 1"))

使用mysql5.7即可。

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

原文:https://www.cnblogs.com/AngelLoveRZZZ/p/10858942.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!