django postgreSQL连接问题

django postgreSQL connection problem

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

1
2
3
4
5
6
7
8
9
10
>>python manage.py shell
>>> FROM django.db import connection
>>> cursor = connection.cursor()
Traceback (most recent CALL LAST):
  File"", line 1, IN
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 250, IN cursor
    cursor = SELF.make_debug_cursor(SELF._cursor())
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 148, IN _cursor
    cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
DataError: unrecognized TIME zone name:"America/Chicago"

但是,当我尝试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
>>> c=connection.cursor()
>>> c

>>> c.execute("select * from test")
Traceback (most recent CALL LAST):
  File"", line 1, IN
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 34, IN EXECUTE
    RETURN SELF.cursor.execute(SQL, params)
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, IN EXECUTE
    RETURN SELF.cursor.execute(query, args)
DatabaseError: CURRENT TRANSACTION IS aborted, commands ignored until END OF TRANSACTION block

>>> connection.commit()
Traceback (most recent CALL LAST):
  File"", line 1, IN
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 202, IN commit
    SELF.set_clean()
  File"/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 147, IN set_clean
    raise TransactionManagementError("This code isn't under transaction management")
TransactionManagementError: This code isn't under transaction management
>>> c.execute("select * from test")
>>> c.fetchone()
(1, 100, u'
abd')

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

1
2
3
4
5
6
7
8
9
10
11
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # ADD 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' OR 'oracle'.
        'NAME': 'mydb',                      # OR path TO DATABASE file IF USING sqlite3.
        'USER': 'postgres',                      # NOT used WITH sqlite3.
        'PASSWORD': '123',                  # NOT used WITH sqlite3.
        'HOST': '/tmp',                      # SET TO empty string FOR localhost. NOT used WITH sqlite3.
        'PORT': '5432',                      # SET TO empty string FOR DEFAULT. NOT used WITH sqlite3.
        #'OPTIONS':TRUE,
    }
}


看起来时区设置不正确。 检查postgresql配置是否支持'America / Chicago'值(它正在运行我的测试服务器...)

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

1
TIME_ZONE = NONE