简体   繁体   中英

IntegrityError: Problem installing fixture

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?

It looks like you've generated fixtures that include Django's default data set, ie 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.

I had the same problem and I solved this way

DB with data to export from

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

New DB to import to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM