Saikumar Kodakandla
Saikumar Kodakandla

Reputation: 3

Django Error while inserting null into date field

Am getting this error while updating date field to null in Django." 'Null' value has an invalid date format. It must be in YYYY-MM-DD format". Please help me if any one knows the solution.

Code: if editBirthday: editBirthday=datetime.strptime(str(editBirthday),"%d-%m-%Y").strftime("%Y-%m-%d") loggedInUser.Birthday = editBirthday else: loggedInUser.Birthday = "Null"

Upvotes: 0

Views: 904

Answers (1)

alecxe
alecxe

Reputation: 473773

You should not set the value to "null", set it to None:

loggedInUser.Birthday = None
loggedInUser.save()

For this to work Birthday model field show be defined with null=True.

See also:

Upvotes: 1

Related Questions