How to troubleshoot Django errors when migrating sqlite database to postgres

Опубликовано: 26 Апрель 2026
на канале: John Solly
1,310
17

Overcome integrity, duplicate keys, and contenttype errors when attempting a database migration from sqlite to postgres for a Django project.

Troubleshooting

To overcome this error
django.db.utils.ProgrammingError: relation "blog_category" does not exist

Uncomment line in forms.py so that categories are not fetched before the table is created

To overcome this error
django.db.utils.IntegrityError: Problem installing fixture Could not load contenttypes.ContentType

Remove auto added contenttypes from django for loading data

$ python3 manage.py shell

from django.contrib.contenttypes.models import ContentType

ContentType.objects.all().delete()

If you run into this error:
Key (id)=(1) already exists

try commenting out pre-save methods (signals.py)

Timestamps
5:00 - Table does not exist
9:12 - Key already exists
10:43 - Another Key already exists error