소스 검색

Documented how to copy a OneToOneField.

Thanks Anton Gilgur for the report and review.
Tim Graham 8 년 전
부모
커밋
2f44fa7f06
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      docs/topics/db/queries.txt

+ 9 - 0
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