Clarify the effects of changing primary keys in models and ModelForms
The primary key documentation explains that changing an existing instance’s primary key and saving it creates a new object alongside the original. See https://docs.djangoproject.com/en/dev/topics/db/models/#field-options
However, it does not explain that if an object with the new primary key already exists, saving the instance updates that object instead.
This behavior also applies to a ModelForm bound to an existing instance when an editable primary key field is included in the form. Changing that field can cause the form to update a different object from the one originally supplied through instance.
We should clarify this existing behavior by:
- Extending the primary key example to demonstrate updating an object that already has the newly assigned primary key. A model with an additional, non-primary-key field would help illustrate which data is updated.
- Expanding Selecting the fields to use to explain the consequences of including an editable primary key field, with a link to the model documentation. Applications should exclude this field unless users are intended to be able to change it.
Change History
(5)
| Triage Stage: |
Unreviewed → Accepted
|
| Triage Stage: |
Accepted → Ready for checkin
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
In b501b84: