Arthur
unread,May 21, 2012, 8:57:05 PM5/21/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hello,
I recently upgraded one of my machines to Django 1.4 to patch a bug related to the use of PostGIS 9.1. I read the documentation on the new support for time zones and added USE_TZ=True to my settings.py file. Nonetheless, when I attempt to load data into my PostGIS database in one of the following ways, I receive a ValueError: Django does not support timezone-aware times. The full traceback is posted at the end.
In the clean() method of my model:
self.datetime = datetime.datetime.combine(self.date, self.time).replace(tzinfo=UTC())
Or in the handle() method of a Command instance:
data_dict['datetime'] = datetime.datetime.combine(data_dict['date'], data_dict['time']).replace(tzinfo=UTC())
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 458, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 219, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 256, in execute
output = self.handle(*args, **options)
File "/usr/local/dev/gass/../gass/bering/management/commands/load_station_data.py", line 108, in handle
data_obj.save() # Save the record to the database only if it doesn't already exist
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 483, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 578, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1581, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 906, in execute_sql
for sql, params in self.as_sql():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 869, in as_sql
for obj in self.query.objs
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 296, in get_db_prep_save
prepared=False)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1258, in get_db_prep_value
return connection.ops.value_to_db_time(value)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 809, in value_to_db_time
raise ValueError("Django does not support timezone-aware times.")
ValueError: Django does not support timezone-aware times.
Any advice is appreciated. Thanks!