summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-12-16 18:34:41 -0500
committerTim Graham <timograham@gmail.com>2016-12-17 08:59:12 -0500
commit0d019287ee3b52266770364eb40dd1a1de6ad083 (patch)
tree2e22d7c656ba08f2ebee91cc9a1fdea2ca003b6b
parente1f93e2b1e0da8cdacbb63167bab8732ffbab872 (diff)
[1.10.x] Documented how to copy a OneToOneField.
Thanks Anton Gilgur for the report and review. Backport of 2f44fa7f069427e2da18a0f6cb2ffc29699f2ca3 from master
-rw-r--r--docs/topics/db/queries.txt9
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index afa1f6be43..a32a3b33d6 100644
--- a/docs/topics/db/queries.txt
+++ b/docs/topics/db/queries.txt
@@ -993,6 +993,15 @@ entry::
entry.save()
entry.authors.set(old_authors)
+For a ``OneToOneField``, you must duplicate the related object and assign it
+to the new object's field to avoid violating the one-to-one unique constraint.
+For example, assuming ``entry`` is already duplicated as above::
+
+ detail = EntryDetail.objects.all()[0]
+ detail.pk = None
+ detail.entry = entry
+ detail.save()
+
.. _topics-db-queries-update:
Updating multiple objects at once