How to manage.py loaddata in Django

一世执手 提交于 2020-07-17 05:41:19

问题


I've being fighting with this command for several hours now.

If I do

python manage.py dumpdata --natural-foreign --> data.json

when I loaddata I get the error

Could not load contenttypes.ContentType(pk=19): duplicate key value violates unique constraint "django_content_type_app_label_76bd3d3b_uniq" DETAIL: Key (app_label, model)=(misuper, stockitem) already exists.

Then if I do

python manage.py dumpdata --natural-foreign --exclude=contenttypes --> data.json

I get a similar error but with a ̣auth.Permission object:

Could not load auth.Permission(pk=55): duplicate key value violates unique constraint "auth_permission_content_type_id_01ab375a_uniq"

And if I do

python manage.py dumpdata --natural-foreign --exclude=contenttypes --exclude=auth --> data.json

when I loaddata I get

User matching query does not exist

Of course, I'm excluding the auth table.

So ... WTF can I do to load the data? All my tests depend on this.

I believe the docs are insufficient. I'm stuck here, please help.


回答1:


Try it like this:

python manage.py dumpdata --natural-foreign \
   --exclude auth.permission --exclude contenttypes \
   --indent 4 > data.json


来源:https://stackoverflow.com/questions/42125730/how-to-manage-py-loaddata-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!