summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorHelen Sherwood-Taylor <helenst@gmail.com>2014-12-24 19:15:48 +0000
committerTim Graham <timograham@gmail.com>2014-12-24 15:07:32 -0500
commit2d0ae995d6b2fb58853fc59802ad781ba03376a6 (patch)
tree7491ffdde4d482f0a4b8bd38b7a5edc8c80723c2 /docs/topics
parent70c965ad4ff06337229c4095a2b2221467781b92 (diff)
[1.6.x] Fixed #24041 -- Documented effect of changing a model instance's primary key.
Backport of 4ccdf6e57f49d7e981dcd88c1db65229b8b92487 from master
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/models.txt17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index fdfa8b3895..916605f6dc 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -212,6 +212,23 @@ ones:
unless you want to override the default primary-key behavior. For more,
see :ref:`automatic-primary-key-fields`.
+ The primary key field is read-only. If you change the value of the primary
+ key on an existing object and then save it, a new object will be created
+ alongside the old one. For example::
+
+ from django.db import models
+
+ class Fruit(models.Model):
+ name = models.CharField(max_length=100, primary_key=True)
+
+ .. code-block:: pycon
+
+ >>> fruit = Fruit.objects.create(name='Apple')
+ >>> fruit.name = 'Pear'
+ >>> fruit.save()
+ >>> Fruit.objects.values_list('name', flat=True)
+ ['Apple', 'Pear']
+
:attr:`~Field.unique`
If ``True``, this field must be unique throughout the table.