automatically dump and load data into django
Mar
18
1
0
Django provides and easy way to backup and load data from your project regardless of which storage engine you're using through [dumpdata] and [loaddata]. If you don't provide the application name after the dumpdata command it'll output the data from all installed applications.
If you want the file to be formated for reading, use the [--indent] option.
manage.py dumpdata flatpages --indent=4 > flatpages.json manage.py loaddata flatpages.json
You can name the dumpdata file [initial_data.json] if you want to automatically load the data file when you [syncdb] and [flush]. It's handy to use with the [--noinput] option to suppress user input if you have an initial_data.json set up.
Be very careful with initial_data.json though as you can unwillingly overwrite data, and you'll be a sad panda. I personally will only locally manage initial_data.json, and will keep it out of the repository at all times.
manage.py syncdb --noinput manage.py flush --noinput