Opened 14 years ago
Closed 14 years ago
#13930 closed (duplicate)
Serialize PKs using the natural key
Reported by: | Juarez Bochi | Owned by: | nobody |
---|---|---|---|
Component: | Core (Serialization) | Version: | |
Severity: | Keywords: | pk, natural key, serialization | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django uses natural keys only to serialize FKs and M2M fields. Serializing the PK with the natural key can also be useful.
Assuming the following object:
{ "pk": 1, "model": "auth.permission", "fields": { "codename": "add_logentry", "name": "Can add log entry", "content_type": [ "admin", "logentry" ] } }, ...
If we use the command loaddata to import this object to the database, an error will be raised if the permission add_logentry already exist with a different id or if another permission has the id 1. That problem can be avoided by using the natural key instead of the pk id number:
{ "pk": [ "add_logentry", "admin", "logentry" ], "model": "auth.permission", "fields": { "codename": "add_logentry", "name": "Can add log entry", "content_type": [ "admin", "logentry" ] } }, ...
Attachments (1)
Change History (2)
by , 14 years ago
Attachment: | pk_natural_key.diff added |
---|
comment:1 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Dupe of #13252