博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TypeError: __init__() missing 1 required positional argument: 'on_delete'
阅读量:4474 次
发布时间:2019-06-08

本文共 968 字,大约阅读时间需要 3 分钟。

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官方文档:

 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即可。

转载于:https://www.cnblogs.com/AngelLoveRZZZ/p/10858942.html

你可能感兴趣的文章
java中如何使用BigDecimal使得Double类型保留两位有效数字
查看>>
范围(地址转换)
查看>>
xcode 提示account验证过期
查看>>
linux 常用处理命令
查看>>
并发中关键字的语义
查看>>
【MFC】消息大全
查看>>
linux shell学习五
查看>>
微软中文MSDN上的一些文章链接
查看>>
复习知识点:GCD多线程
查看>>
Objective-C中的类目(Category),延展(Extension)
查看>>
「学习笔记」wqs二分/dp凸优化
查看>>
面试笔试
查看>>
小波去噪的基本知识
查看>>
Prime Path POJ - 3126
查看>>
程序员的书袋
查看>>
mysql 分库分表转
查看>>
Android开源项目发现---TextView,Button篇(持续更新)
查看>>
1059 C语言竞赛
查看>>
视频算法分类概述
查看>>
MSTAR GUI
查看>>