Opened 9 years ago

Closed 9 years ago

#2512 closed defect (fixed)

[patch] Do not fail on update of a primary-key only table

Reported by: blueyed Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Foo has a model with only id (primary key).


existing_id = 1
foo = Foo( existing_id )

fails like this:

Traceback (most recent call last):
  File "", line 7, in ?
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 183, in save
    db_values + [pk_val])
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 138, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/", line 33, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id`=142' at line 1")

The generated SQL is:

UPDATE `proj_foo` SET  WHERE `id`=%s

A patch to fix this is attached.

Attachments (1)

django_fix_pkonly_update_#2512.diff (1.5 KB) - added by blueyed 9 years ago.

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by blueyed

comment:1 Changed 9 years ago by mtredinnick

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

(In [3548]) Fixed #2512 -- Fixed SQL error when saving existing empty models.

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