#26183 closed Bug (wontfix)
PostgreSQL backend: TimeField is created without time zone
Reported by: | Stefan Heinemann | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | postgres, timezone, time field |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation states that "The PostgreSQL backend stores datetimes as timestamp with time zone."
Sadly, it does not do that with the TimeField, which can easily be seen in db/backend/postgres_psycopg2/base.py line 97. In my opinion, it would be nice to have the same behaviour for both the DateTimeField and the TimeField.
It's easy to change this line to
'TimeField': 'time with time zone'
which does work. But there is a problem:
I wanted to do a pull request so I changed the line. Now I had problems with my migrations file, since I have one that alters a field from TimeField (which was now "with time zone") to a interval. Postgres does not like that and throws
django.db.utils.ProgrammingError: column "duration" cannot be cast automatically to type interval HINT: You might need to specify "USING duration::interval".
So I did that and executed, by hand:
ALTER TABLE "resource_check_testtyperesourcetype" ALTER COLUMN "duration" TYPE interval USING duration::interval;
Now it says: ERROR: cannot cast type time with time zone to interval at character 103
So now I'm not sure if it is even a good idea to change the default behaviour of TimeField to "with time zone"....
Change History (2)
comment:1 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Postgres backend: Time Field is created without time zone, cascading problems when changing this → PostgreSQL backend: TimeField is created without time zone |
This is by design as documented: