【问题标题】:Django 1.4 syncdb + psycopg fails with Timezone ErrorDjango 1.4 syncdb + psycopg 因时区错误而失败
【发布时间】:2013-01-24 07:11:45
【问题描述】:

在 MacOS 上安装 Postgres.app,并使用 Django、dj-database-url 和 psycopg2 初始化 python virtualenv 后,我反复得到:

/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"

为我的 Django 应用程序执行“python manage.py syncdb”时。

关于原因是什么的任何想法?

【问题讨论】:

    标签: python django postgresql psycopg2


    【解决方案1】:

    当我检查 base.py 文件的第 194 行时,我注意到以下代码:

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

    通过将我的 settings.py 文件中的 USE_TZ 参数更改为“False”,我得到了以下错误:

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

    “澳大利亚/珀斯”是我的 settings.py 文件中的时区设置,所以至少它现在正在访问我的时区。

    再次查看 psycopg2 base.py 文件,我注意到以下代码:

    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:
    

    将调试“print conn_tz”放入 base.py 显示 conn_tz(可能是 postgres db 的时区设置)是“Australia/West”。

    将我的 settings.py TIME_ZONE 更改为 'Australia/West' 允许 syncdb 正常运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-18
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多