Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate Django models from mysql to sqlite (or between any two database systems)?

I have a Django deployment in production that uses MySQL.

I would like to do further development with SQLite, so I would like to import my existing data to an SQLite database. I

There is a shell script here to convert a general MySQL dump to SQLite, but it didn't work for me (apparently the general problem isn't easy).

I figured doing this using the Django models must be much easier. How would you do this? Does anyone have any script to do this?

like image 221
daphshez Avatar asked Dec 28 '10 07:12

daphshez


2 Answers

use

manage.py dumpdata > your_file.json

to export your data from the production system (docs).

Then move the file on the development system and run

manage.py loaddata your_file.json

You can also put the file in your_app/fixtures folder with name "initial_data.json" and it will be automatically loaded when you run "manage.py syncdb" (docs).

like image 90
Sergio Morstabilini Avatar answered Oct 26 '22 11:10

Sergio Morstabilini


Have you tried using manage.py dumpdata > datadump and then when the new database is set up correctly, use python manage.py loaddata datadump?

like image 34
Uku Loskit Avatar answered Oct 26 '22 11:10

Uku Loskit