views:

307

answers:

1

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

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 the born datetime object of a person born in the year 1929 and then try to read it, It fails.

Let me re-iterate that the data insertion works fine, but fails during the read. I am assuming that something wrong in going on inside the DB.

I did a set of tests and got to know that it fails whenever I add the person born in or before year 1940. It gives DataError: unable to parse time

I am using PostgreSQL.

Any sort of help would be appreciated. Thanks.

+5  A: 

The only thing I could come up with here can be found in the PostgreSQL docs. My guess is that Django is storing your date in a "reltime" field, which can only go back 68 years. My calculator verifies that 2009-68 == 1941, which seems very close to what you reported.

I would recommend looking over the schema of your table, by running the following command:

$ python manage.py sql appname

See if the datefield in question is a "reltime" field as I suspect. If this is the case, I'm at a loss about how to change it to a more compatable field without messing everything up.

bluejeansummer
I checked, its "born" timestamp with time zone NULL".
aatifh
@bluejeansummer hey, i still couldn't find a way to get rid of this problem.
aatifh
I'm not very familiar with PostgreSQL, as I usually use either SQLite or MySQL for django, so I don't think I can suggest anything you haven't already tried.
bluejeansummer
@bluejeansummer So, you mean this issue works fine on SQLite or MySQL?If it is then its not a django problem rght?
aatifh