Moving Data from One Database to Another with Django

So I have a django database I'm working on and I decided I wanted to do the development in sqlite3 instead of mysql. I decided to do this because it makes it easier, for example, to have someone else work on HTML/CSS if I can just give them a directory, tell them to run a bash script and go to http://localhost:8000, rather than them having to do all that AND setup a mysql server. Sure, that can also be done with a script, but with sqlite things are just a hell of a lot easier in some ways.

I decided I wanted to take the data out of my mysql database and load it into a sqlite db. Not so simple, you can't just take an SQL dump from mysql and import it into sqlite3. I started Googling around for "mysql to sqlite" and didn't really get anywhere. I then realized that Django can already talk to sqlite and mysql transparently without me having to know any SQL. So I thought about writing my own python modules to do this, but it turns out someone has already done it.

The django-extensions project has a command called "dumpscript" that "Generates a Python script that will repopulate the database using objects. The advantage of this approach is that it is easy to understand, and more flexible than directly populating the database, or using XML." This was exactly what I wanted.



Dumpdata/loaddata is not really that easy with full imports.

Many times, models depend on the proper order of importing so a big import fails. 'loaddata' uses the ORM, so it will trigger your models, which are now operating in a very unusual half-empty setup. loaddata seems to create models when the foreignkeys don't exist yet, breaking the import of the actual data later on. The data also includes the contenttypes table, so it should be cleaned first.

I wish it would be so easy, but sadly in practice I didn't always experience that. In the end I typically dumped the data of a few apps separately, and imported them one by one. :-/

Fantastic data on your site, thank you for setting aside an ideal opportunity to impart to us. Astounding understanding you have on this current, it's decent to discover a site that subtle elements such a great amount of data about distinctive specialists. Buy Sizegenetics

Goodness, cool post. I'd like to compose like this as well – requiring significant investment and genuine diligent work to make an incredible article… yet I put things off an excessive amount of and never appear to begin. Much obliged however. movers and packers in pune

I was surfing net and luckily went over this site and discovered exceptionally intriguing stuff here. Its truly enjoyable to peruse. I appreciated a great deal. Much obliged for sharing this awesome data. mens health

Much thanks to you such a great amount for sharing this awesome blog.Very moving and accommodating too.Hope you keep on sharing a greater amount of your ideas.I will love to peruse. crazy bulk review

This is exceptionally instructive substance and composed well for a change. It's pleasant to see that a few individuals still see how to compose a quality post! Buy Male Extra

Add new comment