Solve psycopg2.ProgrammingError: autocommit in Django 1.3.1 + Postgresql run test


When I test my django application which use Postgresql and using python-psycopg2 (Ubuntu 11.10) as wrapper, I got this kind of error :

Run python manage.py myapp :

1
2
3
4
5
6
Creating test database for alias ‘default’…
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py", line 481, in set_autocommit
    self.connection.connection.autocommit = True
psycopg2.ProgrammingError: autocommit cannot be used inside a transaction


It’s show autocommit problem appear while test Django 1.3.1. After searching a while, I got that the solution of this problem is downgrade the python postgresql wrapper into 2.4.1.

You need to uninstall the current packages before run this :

1
2
3
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install python-setuptools python-pip build-essential python-dev libpq-dev
sudo pip install psycopg2==2.4.1

Now try test your django application. It should run well by now 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.