Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1034 closed defect (fixed)

Object save fails for models with mixed-case names using postgresql

Reported by: rfugger at gmail dot com Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using a model named 'myApp.py', the 0.90 build fails the first time I try to save an object to the database (postgresql) with this message:

ProgrammingError at /admin/myApp/units/add/
ERROR: relation "myapp_units_id_seq" does not exist SELECT CURRVAL('myApp_units_id_seq')

The faulty code seems to be in django\core\db\backends\postgresql.py around line 69:

cursor.execute("SELECT CURRVAL('%s_%s_seq')" % (table_name, pk_name))

The proper SQL statement to handle the mixed-case name should be (note the double quotes):

SELECT CURRVAL('"myApp_units_id_seq"')

So this code would probably work (haven't tried):

cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))

Renaming myApp to myapp fixed the problem. This problem didn't occur with previous builds. Other lines of code might have the same missing double quotes.

Change History (1)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [1875]) Fixed #1034 -- Changed get_last_insert_id to quote database table name. Thanks, rfugger

Note: See TracTickets for help on using tickets.
Back to Top