django笔记之fixtures
文章目录
主要参考官方文档
###为何用它
Providing initial data for models
###Where Django finds fixture files
By default, Django looks in the
fixtures
directory inside each app for fixtures. You can set the FIXTURE_DIRS setting to a list of additional directories where Django should look.
###相关指令
python manage.py loaddata APPNAME
python manage.py dumpdata APPNAME
###导出数据 参考这里
python manage.py dumpdata APPNAME
- The output of dumpdata can be used as input for loaddata.
- Outputs to standard output all data in the database associated
with the named application(s)
. - By default dumpdata will output all the serialized data to standard output.
###导入数据 参考这里
python manage.py dumpdata APPNAME
,会自动加载APPNAME/fixtures/xx.json
###实例演示 需求:对myblog(一个app)的数据进行导出与导入 ####导出
python manage.py dumpdata myblog>mydata.json
- 将mydata.json剪切到myblog/fixtures文件夹下 ####导入
python manage.py loaddata myblog
文章作者 种瓜
上次更新 2014-05-30