tags:

views:

64

answers:

2

This is what I want: [Production MySQL Data] -> [Development MySQL Data]

For debugging or improvement, I occasionally need to have a copy of the data running on the production site to be present in my development environment. Obviously I don't want to actually use the production database and manually entering the data is out of the question.

Are there any admin scripts out there that allow this to happen (preferably using Django's management interface) effortlessly and painlessly? What would be ideal would be something like:

manage.py reverse_sync [appname]

Or perhaps manage.py reverse_sync [appname] 500 to get only the first 500 records.

A: 

manage.py dumpdata can dump DB data as a fixture for one or more apps. I don't think there is a way to get only X records through that, though. You could always use shell, do the query and serialize it.

PiotrLegnica
+6  A: 

You want to use

manage.py dumpdata [appname ...]

to get the data out for one or more apps. This will create a fixture file that you can use in unit tests or just a database agnostic format.

To load the data all you need is

manage.py loaddata fixturename [...]

and it will put it in the database the corresponds to your settings.

emeryc
This seems like a good lead; I had forgotten about loaddata. Will do some testing to find out.
T. Stone