skip to Main Content

i wanted to transform my data from sqlite database onto posgres database in django. first of all i write the command:

python -Xutf8 .manage.py dumpdata --indent=4 --output=data.json

to exporting data (in utf-8 encode) in a json file. everything was good and data exported properly, but when i want to import data in postgres (after configuration in settings.py) so i used

python .manage.py loaddata data.json 

and got this error:

django.db.utils.IntegrityError: Problem installing fixture 'C:UsersBardiaDesktopwebappdata.json': Could not load contenttypes.ContentType(pk=7): duplicate key value violates unique constraint "django_content_type_app_label_model_76bd3d3b_uniq"
DETAIL:  Key (app_label, model)=(blog, post) already exists.

can anyone help my in this situation?
thanks a lot

loading data in new postgres database in django

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to a friend's answer and a bit of searching, my problem was solved with the following commands:

    python manage.py shell
    
    >>> from django.contrib.contenttypes.models import ContentType
    >>> ContentType.objects.all().delete()
    

    or do this:

    python manage.py dumpdata --exclude contenttypes
    

  2. Go to Python shell and clear all ContentType data

    python manage.py shell
    
    from django.contrib.contenttypes.models import ContentType
    ContentType.objects.all().delete()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search