Django: loaddata not working

Adrian Lopez picture Adrian Lopez · Feb 9, 2014 · Viewed 13.5k times · Source

I generated a fixture:

python manage.py dumpdata --all > ./mydump.json

I emptied all my databases using:

python manage.py sqlflush | psql mydatabase -U mydbuser

But when i try to use loaddata:

python manage.py loaddata ./mydump.json

I'm recieving this error:

IntegrityError: Could not load tastypie.ApiKey(pk=1): duplicate key 
value violates unique constraint "tastypie_apikey_user_id_key" 
DETAIL:  Key (user_id)=(2) already exists.

I'm having this problem on production and i'm out of ideas. Someone had a similar problem?

Answer

Jan Kaifer picture Jan Kaifer · Feb 28, 2020

Run loaddata with all @recievers commented out because they will be fired when loaddata loads your data. If @recievers create other objects as a sideeffect it will cause collisions.