cannot dump data by using python ./manage.py dumpdata app

7.7k views Asked by At

I created an app in a Django project. For testing purpose, I would like to create fixture files. I found that I can dump my database in order to create fixture automatically if it already has data. I want to use a fixture, so I used the command python ./manage.py dumpdata app, but it returned a list of a ton of \x02. But if I use python ./manage.py auth it runs perfectly. Any idea why my dumpdata shows only \x02.

Thanks in advance.

I attached screenshot as following link:

http://www.cs.ait.ac.th/~fon/wp-content/uploads/2011/01/Screenshot.png

3

There are 3 answers

2
joshcartme On BEST ANSWER

I'm not sure I understand your question completely. When you dump the data you need to store it in a fixture. Check out this blog post: http://solutions.treypiepmeier.com/2008/09/28/use-django-fixtures-to-automatically-load-data-when-you-install-an-app/

Basically do something like this (replace [app_name] with the name of your app):

python manage.py dumpdata [app_name] > [app_name]/fixtures/initial_data.json

You will probably need to create the fixtures directory for your app.

When you run python manage.py syncdb it will automatically look for fixtures in the location [app_name]/fixtures/initial_data.json

Also, if you don't need the ./ when you type python. i.e. you can write

python manage.py ...

rather than

python ./manage.py ...
0
lcltj On

you should run python manage.py dumpdata app > datafile and then load data with python manage.py loaddata datafile

1
Greg Peckory On
import dump

dump.accept(var, 'file eg: text.txt')