According to the Django docs,  a new row is created with the new value
primary key when  when I change the value of a primary key and save
the object.

In this case, I am looking to change the value. So, I use
force_update=True. Instead of changing the value of the primary key, I
get a DatabaseError. Any ideas of what I am doing incorrectly?

class BuildState(models.Model):
    build_state = models.CharField(primary_key=True, max_length=32)

    class Meta:
        db_table = u'buildstate'

    def __unicode__(self):
        return  "BuildState{'build_state' : '%s'}" %
(self.build_state)

>>> from orm.models import BuildState
>>> foo = BuildState.objects.get(build_state='failed')
>>> foo
<BuildState: BuildState{'build_state' : 'failed'}>
>>> foo.build_state='nirvana'
>>> foo.save(force_update=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
410, in save
    self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
476, in save_base
    raise DatabaseError("Forced update did not affect any rows.")
DatabaseError: Forced update did not affect any rows.
>>>
>>>
>>> foo.save()
>>> # This works as expected. A new row is added.
>>>

Thanks,
 -Rick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to