2

After installing Postgres.app on MacOS, and initialising a python virtualenv with Django, dj-database-url, and psycopg2 I repeatedly got:

/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 194, in _cursor
self.ops.set_time_zone_sql(), [tz])
psycopg2.DataError: invalid value for parameter "TimeZone": "UTC"

When executing "python manage.py syncdb" for my Django app.

Any ideas on what the cause is?

4

1 に答える 1

3

When I examined line 194 of the base.py file I noticed the following code:

tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')

By changing the USE_TZ parameter in my settings.py file to 'False' I then got the following error:

psycopg2.DataError: invalid value for parameter "TimeZone": "Australia/Perth"

"Australia/Perth" was the timezone setting in my settings.py file so at least it was accessing my timezone now.

Looking again at psycopg2 base.py file I noticed the following code:

if tz:
                try:
                    get_parameter_status = self.connection.get_parameter_status
                except AttributeError:
                    # psycopg2 < 2.0.12 doesn't have get_parameter_status
                    conn_tz = None
                else:
                    conn_tz = get_parameter_status('TimeZone')

                if conn_tz != tz:

Putting a debug 'print conn_tz' into base.py showed that conn_tz (presumably the timezone setting of the postgres db) was 'Australia/West'.

Changing my settings.py TIME_ZONE to 'Australia/West' allowed syncdb to run normally.

于 2013-01-24T07:11:45.370 に答える