Anoop
Anoop

Reputation: 23

Can't update django datetime field to Null

My code is

Message.objects.filter(id=message_id).update(read_at='Null')

getting this error

ValidationError: [u'Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.']

and the model is

read_at = models.DateTimeField(_("read at"), null=True, blank=True)

Is there any way to update datetime to null? Please help.

Upvotes: 2

Views: 3960

Answers (2)

user
user

Reputation: 695

Message.objects.filter(id=message_id).update(read_at=None)

Upvotes: 2

Peter DeGlopper
Peter DeGlopper

Reputation: 37364

Django update calls are written in Python rather than SQL - use None instead:

Message.objects.filter(id=message_id).update(read_at=None)

Upvotes: 3

Related Questions