6

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

juliocesar
  • 5,706
  • 8
  • 44
  • 63
Fon
  • 299
  • 1
  • 3
  • 16

3 Answers3

11

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 ...
joshcartme
  • 2,717
  • 1
  • 22
  • 34
  • I already did "python manage.py dumpdata app --format=json --indent=8 > app/fixtures/ffixture.json" It doesn't work at all.It shown nothing in file and print only '/x01/x02' something like that on screen. – Fon Jan 28 '11 at 06:36
  • 1
    Try creating a really simple app with one model with one charfield. Populate something in the admin and and run the dumpdata command again and see if it does the same thing. – joshcartme Jan 30 '11 at 00:50
0
import dump

dump.accept(var, 'file eg: text.txt')
biegleux
  • 13,179
  • 11
  • 45
  • 52
Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
0

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

lcltj
  • 1,578
  • 14
  • 13