day52 Django-ORM多表增删改查
day52 Django-ORM多表增删改查 创建关系字段 class Author(models.Model): name=models.CharField(max_length=32) age=models.IntegerField() ad=models.OneToOneField(to="AuthorDetail",to_field="id",on_delete=models.CASCADE) # to_field="id" 可以不写,默认找主键 # to="AuthorDetail", to=可以不用写 # models.SET_NULL 置空 # on_delete=models.CASCADE 默认是级联删除,想做级联更新,直接去数据库修改表结构 class AuthorDetail(models.Model): birthday=models.DateField() telephone=models.CharField(max_length=16) addr=models.CharField(max_length=64) class Publish(models.Model): name=models.CharField(max_length=32) city=models.CharField(max_length=32) class Book(models