I'm having a bit of trouble with django's DateField model field. Shouldn't it be able to accept fiveDaysLater
as a valid date object? When I try to add fiveDaysLater into the database, I get an error saying cannot add null value to date
. However, the second I change the date
field to a regular CharField
, the fiveDaysLater value is added to the database with no problem. fyi if I print fiveDaysLater, I get 2011-09-28
My view:
def myView():
now = datetime.date.today()
fiveDaysLater = now + datetime.timedelta(days=5)
newDate = Spe开发者_开发百科ech(date = fiveDaysLater)
newDate.save()
My model
class Speech(models.Model):
date = models.DateField()
"However, the second I change the date field to a regular CharField..." Just a suspicion but if you made this change in your code, make sure to delete and recreated the Speech table using syncdb, otherwise, sqlite will not be aware of this change. (or you could change the datatype using sqlite exporer for firefox or something like that...)
精彩评论