Django

Code

Ticket #2512 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: blueyed Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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

Calling:

existing_id = 1
foo = Foo( existing_id )
foo.save()

fails like this:

Traceback (most recent call last):
  File "convert_raw.py", line 7, in ?
    foo.save()
  File "/usr/lib/python2.4/site-packages/django/db/models/base.py", line 183, in save
    db_values + [pk_val])
  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 138, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", 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

django_fix_pkonly_update_#2512.diff (1.5 kB) - added by blueyed on 08/09/06 19:54:18.

Change History

08/09/06 19:54:18 changed by blueyed

  • attachment django_fix_pkonly_update_#2512.diff added.

08/09/06 22:55:04 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #2512 ([patch] Do not fail on update of a primary-key only table)




Change Properties
Action