code: RX: 解決辦法: 將第十一行的代碼改為: ...
code:
1 #encoding=utf-8 2 from django.db import models 3 # Create your models here. 4 class BookInfo(models.Model): #創建書本信息類,繼承models.Model 5 booktitle=models.CharField(max_length=20) 6 bookdata=models.DateField() 7 class HeroInfo(models.Model): #創建英雄信息類 8 heroname=models.CharField(max_length=10) 9 herosex=models.BooleanField() 10 herocontent=models.CharField(max_length=50) 11 herobook=models.ForeignKey('BookInfo') #引用外鍵,即BookInfo對象
RX:
解決辦法:
將第十一行的代碼改為:
herobook=models.ForeignKey('BookInfo',on_delete=models.CASCADE,)
即在外鍵值的後面加上 on_delete=models.CASCADE