Skip to content

Use natural foreign keys in test fixtures

Erwan Rouchet requested to merge dumpdata-natural into release-1.6.4

When adding, editing or deleting Django models, we sometimes have to regenerate the test fixtures because we get issues with the Django permissions, as their auto-incremented primary key can get conflicts. We are including Django's auth app in our test fixtures because we needed it for the generic foreign key on rights. I hit this in !2451 (merged).

The dumpdata command supports the --natural-foreign and --natural-primary options which try to use natural foreign keys when available. The content types used in the Right's content_type foreign key are referred to as ["documents", "corpus"] or ["users", "group"] instead of a hardcoded integer primary key. This removes the need for the auth app and reduces the risk of the test fixtures breaking for no good reason.

Edited by Erwan Rouchet

Merge request reports

Loading