id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 13930 Serialize PKs using the natural key Juarez Bochi nobody "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"" ] } }, ... }}}" closed Core (Serialization) duplicate pk, natural key, serialization Unreviewed 0 0 0 0 0 0