开发者

django's DateField model field and acceptable values

开发者 https://www.devze.com 2023-04-06 22:09 出处:网络
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

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...)

0

精彩评论

暂无评论...
验证码 换一张
取 消