Patch to add a --delete option to loaddata management command
|Reported by:||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The attached patch adds a '--delete' option to the loaddata command. This deletes any objects from the database that are not in the fixture. The fixture must contain at least one object of the class for the delete to run.
The result is that loaddata can now insert/update/delete to make a database match the fixture, becoming a sort of 'syncdata' command. A 'dumpdata' followed by 'loaddata --delete' effectively publishes one database onto another. We use this to publish our staging system to live.
The patch contains changes to management/commands/loadata.py, to docs/django-admin.txt and to tests/modeltests/fixtures/models.py. File fixture4.json goes in tests/modeltests/fixtures/fixtures/.