提交表单时,我收到一个IntegrityError (1048, "Column 'paid_on' cannot be null")
.
经过一些研究,我发现很多人通过null=True, blank=True
在 models.py 中包含项目的定义来解决类似的问题,但是将其添加到我的“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()
感谢您的任何意见。