diff --git a/django/db/models/base.py b/django/db/models/base.py
index b5ce39e..ebd67be 100644
a
|
b
|
class Model(object):
|
526 | 526 | # It does already exist, so do an UPDATE. |
527 | 527 | if force_update or non_pks: |
528 | 528 | values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] |
529 | | rows = manager.using(using).filter(pk=pk_val)._update(values) |
530 | | if force_update and not rows: |
531 | | raise DatabaseError("Forced update did not affect any rows.") |
| 529 | if values: |
| 530 | rows = manager.using(using).filter(pk=pk_val)._update(values) |
| 531 | if force_update and not rows: |
| 532 | raise DatabaseError("Forced update did not affect any rows.") |
532 | 533 | else: |
533 | 534 | record_exists = False |
534 | 535 | if not pk_set or not record_exists: |
diff --git a/tests/modeltests/force_insert_update/models.py b/tests/modeltests/force_insert_update/models.py
index db4c5d2..c356312 100644
a
|
b
|
class Counter(models.Model):
|
9 | 9 | name = models.CharField(max_length = 10) |
10 | 10 | value = models.IntegerField() |
11 | 11 | |
| 12 | class InheritedCounter(Counter): |
| 13 | tag = models.CharField(max_length=10) |
| 14 | |
| 15 | class ProxyCounter(Counter): |
| 16 | class Meta: |
| 17 | proxy = True |
| 18 | |
| 19 | class SubCounter(Counter): |
| 20 | pass |
| 21 | |
12 | 22 | class WithCustomPK(models.Model): |
13 | 23 | name = models.IntegerField(primary_key=True) |
14 | 24 | value = models.IntegerField() |
diff --git a/tests/modeltests/force_insert_update/tests.py b/tests/modeltests/force_insert_update/tests.py
index ea0e55f..a5b2dce 100644
a
|
b
|
from __future__ import absolute_import
|
3 | 3 | from django.db import transaction, IntegrityError, DatabaseError |
4 | 4 | from django.test import TestCase |
5 | 5 | |
6 | | from .models import Counter, WithCustomPK |
| 6 | from .models import (Counter, WithCustomPK, InheritedCounter, ProxyCounter, |
| 7 | SubCounter) |
7 | 8 | |
8 | 9 | |
9 | 10 | class ForceTests(TestCase): |
10 | 11 | def test_force_update(self): |
11 | 12 | c = Counter.objects.create(name="one", value=1) |
12 | | # The normal case |
13 | 13 | |
| 14 | # The normal case |
14 | 15 | c.value = 2 |
15 | 16 | c.save() |
16 | 17 | # Same thing, via an update |
… |
… |
class ForceTests(TestCase):
|
38 | 39 | # the data isn't in the database already. |
39 | 40 | obj = WithCustomPK(name=1, value=1) |
40 | 41 | self.assertRaises(DatabaseError, obj.save, force_update=True) |
| 42 | |
| 43 | |
| 44 | class InheritanceTests(TestCase): |
| 45 | def test_force_update_on_inherited_model(self): |
| 46 | a = InheritedCounter(name="count", value=1, tag="spam") |
| 47 | a.save() |
| 48 | a.save(force_update=True) |
| 49 | |
| 50 | def test_force_update_on_proxy_model(self): |
| 51 | a = ProxyCounter(name="count", value=1) |
| 52 | a.save() |
| 53 | a.save(force_update=True) |
| 54 | |
| 55 | def test_force_update_on_inherited_model_without_fields(self): |
| 56 | ''' |
| 57 | Issue 13864: force_update fails on subclassed models, if they don't |
| 58 | specify custom fields. |
| 59 | ''' |
| 60 | a = SubCounter(name="count", value=1) |
| 61 | a.save() |
| 62 | a.value = 2 |
| 63 | a.save(force_update=True) |