关于model
在一对一绑定的时候,有些许更改
from django.db import models class UserInfo(models.Model): user = models.CharField(max_length=32) pwd = models.CharField(max_length=32) class Token(models.Model): user = models.OneToOneField(UserInfo,on_delete=None) token = models.CharField(max_length=64) # 关键字on_delete=None # 2.0版本在源码中取消了on_delete=None,需要手动传递, class OneToOneField(ForeignKey): def __init__(self, to, on_delete, to_field=None, **kwargs): # 源码中取消默认值 kwargs[‘unique‘] = True super().__init__(to, on_delete, to_field=to_field, **kwargs) # 而在django1.11.5和1.8.17版本中,都是有默值的 def __init__(self, to, on_delete=None, to_field=None, **kwargs):