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.
In addition, manage.py is automatically created in each Django project. It does the same thing as django-admin but also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project's settings.py file.
The django-admin.py script should be on your system path if you installed Django via its setup.py utility. If it's not on your path, you can find it in site-packages/django/bin within your Python installation.
makemigrations basically generates the SQL commands for preinstalled apps (which can be viewed in installed apps in settings.py) and your newly created apps' model which you add in installed apps. It does not execute those commands in your database file.
Try it like this:
python manage.py dumpdata --natural-foreign \
--exclude=auth.permission --exclude=contenttypes \
--indent=4 > data.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With