0
提交表單時,我收到一個IntegrityError (1048, "Column 'paid_on' cannot be null")
。Django IntegrityError SQL:1048,不能爲空
經過一番研究後,我發現很多人通過在models.py文件的def中包含null=True, blank=True
解決了類似的問題,但是將其添加到我的'paid_on'模型中並沒有解決我的問題。
這裏是我的models.py類:
class Payment(models.Model):
ad = models.ForeignKey(Ad)
paid = models.BooleanField(default=False)
paid_on = models.DateTimeField('Payment', null=True, blank=True)
amount = models.DecimalField(max_digits=9,decimal_places=2)
pricing = models.ForeignKey(Pricing)
options = models.ManyToManyField(PricingOptions)
def complete(self, amount=0.0):
# clear payment
if self.amount != amount:
return False
self.paid = True
self.paid_on = datetime.datetime.now()
self.save()
# update ad
self.ad.expires_on += datetime.timedelta(days=payment.pricing.length)
self.ad.created_on = datetime.datetime.now()
self.ad.active = True
self.ad.save()
謝謝你的任何輸入。
是的。非常感謝您指出這一點。 –