0

I am trying to migrate my django project from sqlite3 to postgresql. I have done this succesfully in development but getting errors in production.

i have used this command to create dumps:

manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json

then i changed database in my settings.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'dbname',
    'USER': 'username',
    'PASSWORD': 'password',
    'HOST': 'localhost',
    'PORT': '5432',
}

then i exclude contenttypes as follow:

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

but i am getting this error:

django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table 
"django_admin_log" violates foreign key constraint 
"django_admin_log_content_type_id_c4bce8eb_fk_django_co"
DETAIL:  Key (content_type_id)=(7) is not present in table "django_content_type".

please help

10
  • You remove all ContentTypes... So GenericForeignKeys will no longer work, since the table is empty and you thus can no longer refer to a ContentType... Commented Jan 4, 2021 at 15:31
  • i try to remove using ContentType.objects.all().delete() but its still raising error, is there any other way? Commented Jan 4, 2021 at 15:38
  • of course, why do you want to remove the ContentTypes in the first place? Commented Jan 4, 2021 at 15:39
  • @barkatpathan try to run this ContentType.objects.clear_cache() Commented Jan 4, 2021 at 15:46
  • in this answer he suggested to remove them but the error remains same just the key changed from 20 to 7 Commented Jan 4, 2021 at 15:46

1 Answer 1

1

okay i figured out and migrated succesfully. thanks to ankit, Willem Van Onsem and Mostafa Ghadimi

I followed Mostafa Ghadimi's answer here step by step.

also cleared cache suggested byankit

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.