Reputation: 77
I upload my first Django-project into DigitalOcean. After command python manage.py loaddata initial_data.json
, I have received this message:
django.db.utils.IntegrityError: Problem installing fixture '/webapps/django_shop/shop/initial_data.json': Could not load contenttypes.ContentType(pk=3): duplicate key value violates unique constraint "django_content_type_app_label_76bd3d3b_uniq" DETAIL: Key (app_label, model)=(auth, permission) already exists.
How can I fix it?
Upvotes: 1
Views: 3991
Reputation: 531
I had the same problem and I solved this way
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json
python manage.py flush
// Important! Disable all signals on models pre_save and post_save
python manage.py loaddata db.json
// Do not forget to enable all signals that you disabled
Upvotes: 5
Reputation: 4859
It looks like you've generated fixtures that include Django's default data set, i.e. the built-in entries that are inserted normally as part of the first migrate
run for some of Django's plumbing data types.
You should review your fixture process, because content type entries will be created automatically when your (and Django's) apps' migrations are run, so they should not be present in fixtures. It's possible there are other tables that will have this same problem, so now would be a good time to make sure you're not including any other data that would result in this situation.
Upvotes: 3