# Migrating from SQLite to PostgreSQL

**URL:** <https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128>\
**Category:** Using the ORM\
**Created:** [March 15, 2024, 7:17pm UTC](https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128 "2024-03-15T19:17:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![janedenone](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/janedenone/32/12025_2.png) [@janedenone](https://forum.djangoproject.com/u/janedenone)\
**Post date:** [March 15, 2024, 7:17pm UTC](https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128/1 "2024-03-15T19:17:05Z")

</div>

I am aware problems with migrating from SQLite to PostgreSQL [have](https://forum.djangoproject.com/t/cant-transfer-json-data-from-sqlite3-to-postgres/27625) [been](https://forum.djangoproject.com/t/cant-transfer-data-from-sqlite3-to-postgres/18810) [posted](https://forum.djangoproject.com/t/cannot-migrate-from-sqlite-to-postgresql/5141) numerous times, but I hope my issue is sufficiently original.

I dumped the content of my SQLite file, excluding `wagtailsearch.sqliteftsindexentry` as per [this suggestion](https://stackoverflow.com/questions/74638765/invalid-model-identifier-while-migrating-my-data-from-sqlite3-to-postgresql):

```auto
python3 manage.py dumpdata --exclude=wagtailsearch.sqliteftsindexentry > datadump.json

```

switched the DB configuration in `settings.py`, created the DB tables in PostgreSQL:

```auto
python3 manage.py migrate --run-syncdb

```

removed the content types from PostgreSQL database (in the Python shell):

```auto
from wagtail.models import Page
Page.objects.all().delete()
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()

```

and tried to load the JSON file:

```auto
python3 manage.py loaddata datadump.json

```

This results in the following error message:

```auto
django.db.utils.ProgrammingError: Problem installing fixture '/Users/jan/Sites/lms/datadump.json': Could not load wagtailsearch.IndexEntry(pk=32): syntax error in tsvector:

```

The error is located at the beginning of the `body` field value, and is not related to the actual field values (I experimented with deleting certain pages, and the error was consistently located at this position:

```auto
LINE 1: ...e" = 'Impressum', "title" = 'Impressum', "body" = 'Anbieter ...
                                                             ^

```

The same error message is shown if I dump the data in XML format. Any help in debugging this is greatly appreciated. Django 5.0.3 (with Wagtail 6.0.1), PostgreSQL 14.11.

---

<div class="post-metadata">

**Author:** ![ahmeddeveloper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmeddeveloper/32/19935_2.png) [@ahmeddeveloper](https://forum.djangoproject.com/u/ahmeddeveloper)\
**Post date:** [March 16, 2024, 5:54am UTC](https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128/2 "2024-03-16T05:54:23Z")

</div>

Check the JSON file for any problematic characters or syntax issues, particularly in the “body” field of the entry with pk=32.

Or If there are special characters, escape or sanitize them before loading into PostgreSQL database to avoid any syntax errors

And Ensure your PostgreSQL database settings are compatible with the data being imported, especially regarding text encoding and full-text search configurations.

Or Try loading a smaller subset of the data to isolate the issue and identify if it’s specific to certain entries.

Consult Django and Wagtail documentation for migration and data import/export guidelines.

check one by one and you will fix the issue soon.

---

<div class="post-metadata">

**Author:** ![janedenone](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/janedenone/32/12025_2.png) [@janedenone](https://forum.djangoproject.com/u/janedenone)\
**Post date:** [March 16, 2024, 10:21am UTC](https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128/3 "2024-03-16T10:21:24Z")

</div>

Thanks for the reply! I followed your suggestions, but gave up in the end. I kept getting new error messages pointing in different directions.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 17, 2024, 12:37pm UTC](https://forum.djangoproject.com/t/migrating-from-sqlite-to-postgresql/29128/5 "2024-03-17T12:37:59Z")

</div>

What I would suggest you do is dump the original database as SQL insert statements, then apply that SQL to your new database.

This should provide you with more detailed error information for figuring out where the problem lies.
