Sean's i/o Stream

Musings-as-a-Service

Moving django data between vendors

  • May 19, 2012
  •   category: blog
  • tags: database, django, migration, postgresql, python, sqlite3

The out of the box tooling makes this pretty easy, just a few commands to get the data to a suitable serialized format, and one more to bring it into the new target.

In order to prep for the new database, I created another db definition in my settings.py file for default, and updated the existing database to ‘old’ for the migration.

DATABASES = {
    'old': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/home/user/djangoapps/vl4rl/vl4rl/db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    },
    'default' : {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'user_vl4rl',                      # Or path to database file if using sqlite3.
        'USER': 'user_vl4rlu',                      # Not used with sqlite3.
        'PASSWORD': '***',                  # Not used with sqlite3.
        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
    }
}

Export:

./manage.py dumpdata --indent 4 --exclude auth --database=old > vl4rl.20120519.json

Import:

./manage.py syncdb
./manage.py loaddata vl4rl.20120519.json
Reference:
Back to Top