One good way to do this is by using fixtures, especially initial_data fixtures.
A device is a collection of files containing serialized database content. So, it looks like backing up a database, but somehow Django knows about it easier to use and will have additional benefits when you come to do things like unit testing.
You can create a device from the data currently in your database using django-admin.py dumpdata . By default, the data is in JSON format, but other options, such as XML, are available. A good place to store fixtures is the fixtures subdirectory of application directories.
You can download the patch using django-admin.py loaddata , but more significantly, if your device has a name like initial_data.json , it will be automatically loaded when you run syncdb , saving the import problem yourself.
Another advantage is that when you run manage.py test to run tests per unit of time, the source data device will also be loaded in the time test database.
Of course, this will work when you add attributes to models and columns in the database. If you delete a column from the database, you will need to update your fixture to remove data for this column, which may be difficult.
This works best when many small database changes are made during development. To update production databases, a better manually generated SQL script may work.
Dave Webb Aug 30 '08 at 14:57 2008-08-30 14:57
source share