I'm using flatpages in a site that I'm developing in a locally server. I need to backup the flatpage's data for use it in the final server. Does anyone know how to do it?
+6
A:
On your local server run this:
python manage.py dumpdata flatpages --indent=2 > backup.json
Then copy backup.json to your final server and load it with:
python manage.py loaddata backup.json
Van Gale
2009-03-06 07:04:57
thanks!! works like a charm! another question: in the same way can i back up the super user data?
z3a
2009-03-06 07:29:16
Yes, dumpdata will dump whatever models you pass on the command line and you can give more than one so, for example, you can do "python manage.py dumpdata auth flatpages" to get both the auth models and the flatpages models.
Van Gale
2009-03-06 07:34:09
Although one thing with auth that can be a problem. You won't be able to loaddata if you already have auth models installed on your final server. So you need to do "python manage.py syncdb --noinput" to prevent syncdb from creating first superuser (or say "no" when it prompts you).
Van Gale
2009-03-06 07:37:02
Err, also forgot, you can't prevent syncdb from creating the permissions tables, so you have to delete those from your json file before loading it with loaddata.
Van Gale
2009-03-06 07:39:39
Loaddata handles existing data pretty well (overwrites if the PK is the same). The real problem with auth is permissions/contenttypes, as they can be created in different orders at different times, so if you overwrite one you'd better do the other too (and you may still have issues with other FKs).
Carl Meyer
2009-03-06 19:30:51