Problems with contenttypes when loading a fixture in Django

manage.py dumpdata --natural will use a more durable representation of foreign keys. In django they are called “natural keys”. For example:

  • Permission.codename is used in favour of Permission.id
  • User.username is used in favour of User.id

Read more: natural keys section in “serializing django objects”

Some other useful arguments for dumpdata:

  • --indent=4 make it human readable.
  • -e sessions exclude session data
  • -e admin exclude history of admin actions on admin site
  • -e contenttypes -e auth.Permission exclude objects which are recreated automatically from schema every time during syncdb. Only use it together with --natural or else you might end up with badly aligned id numbers.

Leave a Comment