What is best practice when using dumpdata --natural-key?

Viewed 20

When using dumpdata, Django recommends using natural_key() to serialize objects that refer to Permission or ContentType:

--natural-foreign

Uses the natural_key() model method to serialize any foreign key and many-to-many relationship to objects of the type that defines the method. If you’re dumping contrib.auth Permission objects or contrib.contenttypes ContentType objects, you should probably use this flag. See the natural keys documentation for more details on this and the next option.

This means that rather than dumping foreignkey contentype with pk=1, it is dumped as:

"content_type": [
  "myapp",
  "mymodel"
],
  • Why would you not always use --natural-key?
  • What use cases are there where --natural-key would be inappropriate?
0 Answers
Related