鍍金池/ 問答/Python  HTML/ Django保存數(shù)據(jù)時(shí)報(bào)錯(cuò) NOT NULL constraint failed

Django保存數(shù)據(jù)時(shí)報(bào)錯(cuò) NOT NULL constraint failed

添加數(shù)據(jù)后保存時(shí)報(bào)錯(cuò)

NOT NULL constraint failed:booktest_bookinfo.bpub_data

源代碼

class BookInfo(models.Model):
    btitld=models.CharField(max_length=20)
    bpub_data=models.DateTimeField()

class HeroInfo(models.Model):
    hname=models.CharField(max_length=10)
    hgender=models.BooleanField()
    hcontent=models.CharField(max_length=1000)
    hbook=models.ForeignKey(BookInfo, on_delete=models.CASCADE)

圖片描述

回答
編輯回答
逗婦乳

NOT NULL constraint failed:booktest_bookinfo.bpub_data

意思是非空限制失敗

可能是添加數(shù)據(jù)時(shí),bpub_data為空了。試著給這個(gè)字段填上值再試試

2017年2月3日 07:40
編輯回答
不舍棄

變量名拼寫錯(cuò)誤:
BookInfo中, 應(yīng)該是btitle而不是btitld, 應(yīng)該是bpub_date而不是bpub_data

2017年5月14日 20:28