Joren
Joren

Reputation: 3315

Wagtail moving sqlite to postgres database

The issue

I have an empty (migrated) postgres database to which I want to move the data from my sqlite database.

What I've tried

Used versions

Related

Problems with contenttypes when loading a fixture in Django

Upvotes: 7

Views: 1920

Answers (2)

allcaps
allcaps

Reputation: 11248

With pgloader you can execute command instructions to load data from SQLite into Postgres.

Install on OSX with Homebrew:

brew install pgloader

Create a script file. Eg migrate.script:

load database
     from sqlite:///path/to/db.sqlite3
     into postgresql:///yourpostgresdbname

 with include drop, create tables, create indexes, reset sequences

  set work_mem to '16MB', maintenance_work_mem to '512 MB';

Run it:

pgloader migrate.script

I did a testdrive with a SQLite database containing a minimal Wagtail project (some pages, revisions and images) and it worked perfectly.

Upvotes: 2

Ian Cameron
Ian Cameron

Reputation: 39

I managed something when I moved my Wagtail site from sqlite to Postgres, so just adding for reference.

I used this website as a base, but ran into an error when I couldn't delete ContentType objects right away due to a foreign key issue, as follows:

django.db.utils.IntegrityError: insert or update on table "wagtailcore_page" violates foreign key constraint "wagtailcore_page_content_type_id_c28424df_fk_django_co"

DETAIL: Key (content_type_id)=(1) is not present in table "django_content_type".

Seemed like it was due to Wagtail page objects, so executed the following two lines in the Django shell first. Was then able to follow the rest of the instructions on that page, executing the ContentType deletion and the import.

from wagtail.core.models import Page
Page.objects.all().delete()

Upvotes: 0

Related Questions