diff --git a/django/db/models/base.py b/django/db/models/base.py
a
|
b
|
|
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
a
|
b
|
|
8 | 8 | name = models.CharField(max_length = 10) |
9 | 9 | value = models.IntegerField() |
10 | 10 | |
| 11 | |
| 12 | class InheritedCounter(Counter): |
| 13 | tag = models.CharField(max_length=10) |
| 14 | |
| 15 | |
| 16 | class ProxyCounter(Counter): |
| 17 | class Meta: |
| 18 | proxy = True |
| 19 | |
| 20 | |
| 21 | class SubCounter(Counter): |
| 22 | pass |
| 23 | |
| 24 | |
11 | 25 | class WithCustomPK(models.Model): |
12 | 26 | name = models.IntegerField(primary_key=True) |
13 | 27 | value = models.IntegerField() |
diff --git a/tests/modeltests/force_insert_update/tests.py b/tests/modeltests/force_insert_update/tests.py
a
|
b
|
|
1 | 1 | from django.db import transaction, IntegrityError, DatabaseError |
2 | 2 | from django.test import TestCase |
3 | 3 | |
4 | | from models import Counter, WithCustomPK |
| 4 | from models import (Counter, WithCustomPK, InheritedCounter, ProxyCounter, |
| 5 | SubCounter) |
5 | 6 | |
6 | 7 | |
7 | 8 | class ForceTests(TestCase): |
8 | 9 | def test_force_update(self): |
9 | 10 | c = Counter.objects.create(name="one", value=1) |
| 11 | |
10 | 12 | # The normal case |
11 | | |
12 | 13 | c.value = 2 |
13 | 14 | c.save() |
| 15 | |
14 | 16 | # Same thing, via an update |
15 | 17 | c.value = 3 |
16 | 18 | c.save(force_update=True) |
… |
… |
|
36 | 38 | # the data isn't in the database already. |
37 | 39 | obj = WithCustomPK(name=1, value=1) |
38 | 40 | self.assertRaises(DatabaseError, obj.save, force_update=True) |
| 41 | |
| 42 | |
| 43 | class InheritanceTests(TestCase): |
| 44 | def test_force_update_on_inherited_model(self): |
| 45 | a = InheritedCounter(name="count", value=1, tag="spam") |
| 46 | a.save() |
| 47 | a.save(force_update=True) |
| 48 | |
| 49 | def test_force_update_on_proxy_model(self): |
| 50 | a = ProxyCounter(name="count", value=1) |
| 51 | a.save() |
| 52 | a.save(force_update=True) |
| 53 | |
| 54 | def test_force_update_on_inherited_model_without_fields(self): |
| 55 | ''' |
| 56 | Issue 13864: force_update fails on subclassed models, if they don't |
| 57 | specify custom fields. |
| 58 | ''' |
| 59 | a = SubCounter(name="count", value=1) |
| 60 | a.save() |
| 61 | a.value = 2 |
| 62 | a.save(force_update=True) |