0

Foreground

Hi. I´m uploading my Django app database to my Heroku production environment. When I try to manage.py loaddata I get the following error:

django.db.utils.IntegrityError: Problem installing fixtures: insert or update in table "catalog_contactos" violates key constraint.

I found this post where someone suggests that first you should load models that are the base for foreign key: related post

Also I found this post that refers to moving a database to another app (the production version for example). Basically it says:

When you backup whole database by using dumpdata command, it will backup all the database tables

If you use this database dump to load the fresh database(in another django project), it can be causes IntegrityError (If you loaddata in same database it works fine)

To fix this problem, make sure to backup the database by excluding contenttypes and auth.permissions tables

Link to the post

My code

Following that suggestions I do:

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

Then on the server I run the following code and get the integrity error:

heroku run python manage.py loaddata data.json

Should I dumpdata model by model and loaddata them in a certaing order? Or I´m coding something wrong? Any clues?

Thanks in advance!

Update

Could this "Natural keys" issue be the solutuion? Django serializing objects

commadelimited
  • 5,656
  • 6
  • 41
  • 77
Francisco Ghelfi
  • 872
  • 1
  • 11
  • 34

1 Answers1

0

When I had integrity error with django/postgreSQL I did DROP TABLE table in postgreSQL.

vvtli
  • 1
  • 3