Opened 9 years ago

Closed 9 years ago

Last modified 8 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
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: UI/UX:


Using a model named '', 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\ 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.

Attachments (0)

Change History (1)

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.