Skip to content

Migrating data between instances

Matthew Hanlon edited this page Oct 7, 2015 · 4 revisions

The database used in local development is a SQLite database, whereas in production the database is MySQL. We cannot simply import a MySQL database dump into our SQLite database because of syntax differences between the two platforms. However, Django does provide a nice way to migrate data independent of the backing datastore.

To move data between instances use the Django dumpdata command.

Run an instance of the portal container with a production environment config. Map in a local volume to export data to:

user@localhost   $ docker run -it --rm -v /path/to/datadump:/datadump --env-file chameleon.env portal_portal bash
root@<container> # ./manage.py dumpdata > /datadump/datadump.json
root@<container> # exit

Then we can use the loaddata command to load datadump.json into a secondary instance. We also need to flush the local database to empty all existing data. IMPORTANT: if you need to backup your local database do it now!

user@localhost   $ docker-compose up -d
user@localhost   $ cp db.sqlite3 db.sqlite3.bak
user@localhost   $ cp /path/to/datadump/datadump.json .
user@localhost   $ docker exec -it portal_django_1 bash
root@<container> # ./manage.py flush --no-initial-data
root@<container> # ./manage.py loaddata datadump.json
Clone this wiki locally