Datetime Date in Django

I am trying to add a datetime object to a person. Whenever the year of birth is less than 1942, I get a strange DataError: unable to parse time error when reading data back from the database.

 class Person(models.Model): """A simple class to hold the person info """ name = models.CharField(max_length=100) born = models.DateTimeField(blank=True, null=True) 

Whenever I try to add a born datetime object to a person born in 1929, and then try to read it, it fails.

Let me repeat the iteration that the data insert works fine, but it fails while reading. I guess something is wrong inside the database.

I did a test suite and found out that it fails when I add a person born in or before 1940. It gives a DataError: unable to parse time

I am using PostgreSQL.

Any help would be greatly appreciated. Thanks.

+4
source share
1 answer

The only thing I can find here can be found in PostgreSQL Docs . I assume that Django stores your date in the "reltime" field, which can only return after 68 years. My calculator confirms that 2009-68 == 1941, which seems very close to what you reported.

I would recommend looking at your table schema by running the following command:

 $ python manage.py sql appname 

See if this date field is a "reltime" field, as I suspect. If so, I don’t understand how to change it to a more compatible field without ruining everything.

+6
source

All Articles