无法使用python ./manage.py dumpdata app转储数据

时间:2022-06-15 00:58:41

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.

我在Django项目中创建了一个应用程序。出于测试目的,我想创建夹具文件。我发现我可以转储我的数据库,以便在已有数据的情况下自动创建夹具。我想使用一个fixture,所以我使用了命令python ./manage.py dumpdata app,但它返回了一个大量的\ x02列表。但是,如果我使用python ./manage.py auth它运行完美。知道为什么我的dumpdata只显示\ 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 个解决方案

#1


9  

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/

我不确定我完全理解你的问题。转储数据时,需要将其存储在夹具中。看看这篇博文: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):

基本上做这样的事情(用您的应用程序的名称替换[app_name]):

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

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

您可能需要为您的应用程序创建fixtures目录。

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

当你运行python manage.py syncdb时,它会自动在[app_name] /fixtures/initial_data.json位置查找灯具。

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

此外,如果您在键入python时不需要./。即你可以写

python manage.py ...

rather than

python ./manage.py ...

#2


0  

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

你应该运行python manage.py dumpdata app> datafile然后用python manage.py loaddata datafile加载数据

#3


0  

import dump

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

#1


9  

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/

我不确定我完全理解你的问题。转储数据时,需要将其存储在夹具中。看看这篇博文: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):

基本上做这样的事情(用您的应用程序的名称替换[app_name]):

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

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

您可能需要为您的应用程序创建fixtures目录。

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

当你运行python manage.py syncdb时,它会自动在[app_name] /fixtures/initial_data.json位置查找灯具。

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

此外,如果您在键入python时不需要./。即你可以写

python manage.py ...

rather than

python ./manage.py ...

#2


0  

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

你应该运行python manage.py dumpdata app> datafile然后用python manage.py loaddata datafile加载数据

#3


0  

import dump

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