代码的一个小小Bug有时候会让人焦头烂额,费了很大劲搞明白的问题,如果不记录下来,是很容易遗忘的! 定义一个类,如果按照以下的方式使用,则会出现TypeError: testFunc() missing 1 required positional argument: 'self'.如果认真细究的话,笔者曾反复修改参数,但是于事无补. 在Python中,应该先对类进行实例化,然后在应用类,如下图所示.注意,实例化的过程是应该待括号的. 总结:Python中,类应该先实例化,然后再使用类!…
原因: 在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…
原因: 在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…
在添加外键的时候,在括号里添加on_delete=models.CASCADE即可 on_delete=models.CASCADE是级联删除的意思,意思就是说当你更新或删除主键表,那外键表也会跟随一起更新或删除.…
先贴一下源码: base.py文件如下: from selenium import webdriver class Page(object): ''' 页面基础类,用于所有页面的继承 ''' rb_url = 'http://XXXXX' def __init__(self,selenium_driver,base_url=rb_url): self.driver = selenium_driver self.base_url = base_url self.timeout = 30 def o…
原因 执行命令 python manage.py makemigrations 报错 TypeError: __init__() missing 1 required positional argument: 'on_delete' 定义外键报错 解决办法 字段名称 = models.ForeignKey('表名', on_delete=models.CASCADE) on_delete=models.CASCADE 在 django2.0之前有默认值,之后版本就需要显式指定…
在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: 'on_delete' 解决方法: 在连接外键时加上: on_delete=models.CASCADE…
Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete' 一.分析 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing 1 required positional argument: 'on_delete' 二.解决方案 在外键值…
进行数据库迁移的时候,显示  TypeError: __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…