[Django] dumpdata to avoid conflicts and errors at loaddata

· 1 min read
[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

Related Articles

Mixed Signals
· 5 min read
JSHeroes 2024
·
Talking at ITDays
· 1 min read
Vue & Nuxt Meetup
· 1 min read
JSHeroes 2023
· 1 min read