【问题标题】:django postgreSQL connection problemdjango postgreSQL 连接问题
【发布时间】:2011-07-28 11:07:06
【问题描述】:

我在 Django 中连接 PostgreSql 时遇到问题

>>python manage.py shell >>> 从 django.db 导入连接 >>> 光标 = connection.cursor() 回溯(最近一次通话最后): 文件“”,第 1 行,在 光标中的文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py”,第 250 行 光标 = self.make_debug_cursor(self._cursor()) _cursor 中的文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py”,第 148 行 cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) DataError:无法识别的时区名称:“美国/芝加哥”

但是,当我尝试时

>>> c=connection.cursor() >>> c >>> c.execute("从测试中选择 *") 回溯(最近一次通话最后): 文件“”,第 1 行,在 文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py”,第 34 行,在执行 返回 self.cursor.execute(sql, params) 执行中的文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py”,第 44 行 返回 self.cursor.execute(查询,参数) DatabaseError:当前事务被中止,命令被忽略,直到事务块结束 >>> 连接.commit() 回溯(最近一次通话最后): 文件“”,第 1 行,在 提交中的文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py”,第 202 行 self.set_clean() 文件“/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py”,第 147 行,在 set_clean raise TransactionManagementError("此代码不在事务管理下") TransactionManagementError:此代码不在事务管理下 >>> c.execute("从测试中选择 *") >>> c.fetchone() (1, 100, u'abd')

我不知道问题出在哪里
我做了谷歌,但没有帮助,有人可以帮忙吗?非常感谢。
我的设置是:

数据库 = { '默认': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', # 添加 'postgresql_psycopg2'、'postgresql'、'mysql'、'sqlite3' 或 'oracle'。 'NAME': 'mydb', # 如果使用 sqlite3,则为数据库文件的路径。 'USER': 'postgres', # 不与 sqlite3 一起使用。 'PASSWORD': '123', # 不与 sqlite3 一起使用。 'HOST': '/tmp', # 设置为本地主机的空字符串。不与 sqlite3 一起使用。 'PORT': '5432', # 默认设置为空字符串。不与 sqlite3 一起使用。 #'选项':是的, } }

【问题讨论】:

  • 如果您找到适合您的解决方案,请确保您接受它。

标签: django postgresql


【解决方案1】:

时区设置似乎不正确。检查您的 postgresql 配置是否支持值“America/Chicago”(它正在运行我的测试服务器......)

尝试将其设置为None - 也许它会帮助你:

TIME_ZONE = None

【讨论】:

    猜你喜欢
    • 2021-11-18
    • 2011-04-10
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2015-09-19
    • 1970-01-01
    相关资源
    最近更新 更多