Reputation: 490
Im trying to do the below command but im getting this long error. I have also tried to do go into the dbshell to trucanate as i saw suggested elsewhere but im getting the error that psql is not install or path found even though it should be.
I have been succesful in managing to get my tables in the postgres database but their are all empty except a few, which i find strange. My Json dump file has everything it needs in it but it wont transfer over.
Anyone have any ideas?
(venv) DEMOPROJECT>python manage.py loaddata "datadump.json"
Traceback (most recent call last):
File "\PycharmProjects\WebP1\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "django_content_type_app_label_model_76bd3d3b_uniq"
DETAIL: Key (app_label, model)=(admin, logentry) already exists.
django.db.utils.IntegrityError: Problem installing fixture '\DEMOPROJECT\datadump.json': Could not load contenttypes.ContentType(pk=1): duplicate key value violates unique constraint "django_content_type_app_label_model_76bd3
d3b_uniq"
DETAIL: Key (app_label, model)=(admin, logentry) already exists.
Upvotes: 0
Views: 1397
Reputation: 2921
ContentType is a sort of registry of an app's models, intended as an interface to be able to access information about a model without having to know a whole lot about the model specifics.
The django auth framework uses ContentType to map permissions to models.
The django admin app tracks changes to its objects via the model LogEntry
which itself uses ContentTypes (that's the model that is causing the error you've posted).
If ContentType is queried for a model that it doesn't know already, a new record with that model is created: that means that the makeup of the ContentType table can differ from environment to environment - it depends on the order in which models are requested in.
Seeing that your dump already contains data for ContentType, and assuming that for any model that uses ContentType, the dump also contains the references to that new ContentType table, you should be fine deleting all entries that are currently in the ContentType table of your local, outdated database:
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
You should then be able to load your datadump without a problem.
You can make a backup of the contents of your ContentType, if you want to make sure nothing gets lost:
python manage.py dumpdata contenttypes.ContentType
Upvotes: 2
Reputation: 5515
Notice that your unique index is getting duplicate: Key (app_label, model)=(admin, logentry) already exists.
That would mean one of following:
Upvotes: 0