[Django] dumpdata to avoid conflicts and errors at loaddata

When you backup whole database by using dumpdata command, it will backup all the database tables.

If you use this database dump to load the fresh database(in another django project), it can be causes IntegrityError (If you loaddata in same database it works fine).

To fix this problem, make sure to backup the database by excluding contenttypes and auth.permissions tables.

./manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json

Long version, with natural primary and foreign keys:

manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission --indent 4

Leave a Reply

Your email address will not be published. Required fields are marked *