Question

A few days ago I write a project in django1.4 using the admin capabilities with the intention to make a CRUD for debug data migrated from a legacy system to a new system (the migration wasn't entirely successful), I write it using django 1.4 and with a copy of production database in my laptop, but in my linux I use postgresql9.1, so, when I tried to config the project to a testing databes in the original server (postgresql8.1) I got errors in the syncdb and migrate statments:

File "/home/diegueus9/webapps/fixsysandinos/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/diegueus9/webapps/fixsysandinos/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: syntax error at or near "RETURNING"
LINE 1: ...") VALUES (E'permission', E'auth', E'permission') RETURNING ...

So, I did a little research and I found the ticket #10467 (currently closed) in django, which says that the use of statment RETURNING introduces an error in postgresql 8.1, because it doesn't support that syntax until 8.2 (I think), the bug appears as closed 8 months ago but I think in some point was reintroduced. In the thread of the tickets says that the problem can be related to autocommit behavior and talks about connection.features.can_return_id_from_insert.

So the questions are:

It is a bug that have to be reopened? I must disable autocommit behavior and assume the risks (I don't hope so) or maybe through settings I can set connection.features.can_return_id_from_insert to False and in this way accomplish my goal?

Was it helpful?

Solution

When upgrade the database or downgrade your django version is not an option because is a requirement of a client, you can still django1.4 under your own responsability you can disable the RETURN statement setting can_return_id_from_insert to False in django.db.backends.postgresql_psycopg2.base in the line 77. But this affects the behavior of django so you really must or should use something like virtualenvwrapper

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top