Django IntegrityError SQL: 1048, cannot be null
Question
When submitting a form, I receive an IntegrityError (1048, "Column 'paid_on' cannot be null")
.
After some research I had discovered that many people had solved similar issues by including null=True, blank=True
in an item's def in models.py, but adding this to my 'paid_on' model has not solved my issue.
Here is the class from my 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()
Thank you for any input.
Solution
Just adding this to your model won't help as your database still has the restriction. If you want/need to do migrations (you change parts of your models.py and it should change your database) have a look at south which supports migrations for Django
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow