解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE 原因: 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing 1 required positional argument: 'on_delete'举例说明:us…
Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete' 一.分析 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing 1 required positional argument: 'on_delete' 二.解决方案 在外键值…
from django.db import models # Create your models here. class Category(models.Model): caption = models.CharField(max_length=) class ArticleType(models.Model): caption = models.CharField(max_length=) class Article(models.Model): title = models.CharFie…
原因: 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing 1 required positional argument: 'on_delete'举例说明:user=models.OneToOneField(User)owner=models.ForeignKey(UserProfile)需要改成:user=models.OneToOneField(User…
1.Django2.0之后使用外键时遇到 __init__() missing 1 required positional argument: 'on_delete' 需要在外键创建时给on_delete参数赋值.models.CASCADE是老版本的默认值. publish = models.ForeignKey("Publish", on_delete=models.CASCADE)…
进行数据库迁移的时候,显示  TypeError: __init__() missing 1 required positional argument: 'on_delete' 图示: 出现原因: 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错: TypeError: __init__() missing 1 required positional argument: 'on_delete' 修改:…
sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __init__() missing 1 required positional argument: 'on_delete'缺少一个参数  'on_delete'加上就好了sgrade = models.ForeignKey("Grades",on_delete=models.CASCADE,)…
python: 3.6.4 django: 2.0 models.py 代码如下 # coding: utf-8 from django.db import models from django.contrib.auth.models import User # Create your models here. class Category(models.Model): name = models.CharField(max_length=100) class Tag(models.Model)…
原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html…
报错信息: E:\Python\s6day103>python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "F:\Program Files (x86)\Python3.6\lib\site-packages\django\…