1
我在DjangoDjango的PostgreSQL的連接問題
>>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"
連接的PostgreSQL有一個問題,但是,當我試圖
>>> 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')
我不知道問題出在哪裏
我做了谷歌,但它沒有幫助,任何人都可以幫忙嗎?非常感謝。
我的設置是:
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, } }
如果你找到一個適合你的解決方案,確保你接受它。 – intgr 2011-04-03 13:50:10