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

3

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

Quesada answered 28/1, 2011 at 5:55 Comment(1)
what does python manage.py dumpdata app | head show?Ripp
R
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 ...
Reiterant answered 28/1, 2011 at 6:17 Comment(2)
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.Quesada
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.Reiterant
S
0

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

Snapper answered 28/1, 2011 at 6:26 Comment(0)
T
0
import dump

dump.accept(var, 'file eg: text.txt')
Telpherage answered 2/9, 2012 at 16:8 Comment(1)
I get "ImportError: No module named dump", where can I found/install that module?Incunabula

© 2022 - 2024 — McMap. All rights reserved.