diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
a
|
b
|
|
225 | 225 | db = router.db_for_read(self.related.model, instance=instance) |
226 | 226 | rel_obj = self.related.model._base_manager.using(db).get(**params) |
227 | 227 | setattr(instance, self.cache_name, rel_obj) |
| 228 | setattr(rel_obj, self.related.field.name, instance) |
228 | 229 | return rel_obj |
229 | 230 | |
230 | 231 | def __set__(self, instance, value): |
diff --git a/tests/regressiontests/one_to_one_regress/models.py b/tests/regressiontests/one_to_one_regress/models.py
a
|
b
|
|
26 | 26 | place = models.OneToOneField(Place, null=True) |
27 | 27 | serves_cocktails = models.BooleanField() |
28 | 28 | |
| 29 | def unlink_place(self): |
| 30 | self.place = None |
| 31 | self.save() |
| 32 | |
29 | 33 | class Favorites(models.Model): |
30 | 34 | name = models.CharField(max_length = 50) |
31 | 35 | restaurants = models.ManyToManyField(Restaurant) |
diff --git a/tests/regressiontests/one_to_one_regress/tests.py b/tests/regressiontests/one_to_one_regress/tests.py
a
|
b
|
|
128 | 128 | Target.objects.exclude(pointer2=None), |
129 | 129 | [] |
130 | 130 | ) |
| 131 | |
| 132 | def test_not_delete_parent(self): |
| 133 | """Regression test for #14043 |
| 134 | |
| 135 | Deleting a parent object should not delete the (ex) child after breaking |
| 136 | their link. |
| 137 | """ |
| 138 | bar = UndergroundBar.objects.create(place=self.p1, serves_cocktails=False) |
| 139 | self.p1.undergroundbar.unlink_place() |
| 140 | self.p1.delete() |
| 141 | self.assertEqual(UndergroundBar.objects.count(), 1) |