Opened 15 years ago
Closed 15 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 , 15 years ago
| Attachment: | pk_natural_key.diff added |
|---|
comment:1 by , 15 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Dupe of #13252