Django saves data Times error NOT NULL constraint failed

Save Times error after adding data

NOT NULL constraint failed:booktest_bookinfo.bpub_data

Source code

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)

Mar.21,2021

NOT NULL constraint failed:booktest_bookinfo.bpub_data

means non-empty restriction failed

it is possible that bpub_data was empty when data was added. Try to fill in the value for this field and try

again.

variable name misspelled:
in BookInfo , it should be btitle instead of btitld , it should be bpub_date instead of bpub_data

.
Menu