diff options
| author | Tim Graham <timograham@gmail.com> | 2016-12-16 18:34:41 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-17 08:39:52 -0500 |
| commit | 2f44fa7f069427e2da18a0f6cb2ffc29699f2ca3 (patch) | |
| tree | 74bd512e7f0d14b54c4d80d933ae8a96851aaedf /docs/topics | |
| parent | 8dac9890a5941e7b59ea0ebebed400965941fe09 (diff) | |
Documented how to copy a OneToOneField.
Thanks Anton Gilgur for the report and review.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/db/queries.txt | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 654c2c5c4a..0d69099fa7 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -985,6 +985,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 |
