Django使用manage.py备份与恢复数据
Django dumpdata and loaddata
dumpdata command
- It is a django management command, which can be use to backup(export) you model instances or whole database
dumpdata for basic database dump
- Following command will dump whole database in to a
db.jsonfile
./manage.py dumpdata > db.json
dumpdata for backup specific app
- Following command will dump the content in django
adminapp intoadmin.jsonfile
./manage.py dumpdata admin > admin.json
dumpdata for backup specific table
- Following command will dump only the content in django
admin.logentrytable
./manage.py dumpdata admin.logentry > logentry.json
- Following command will dump the content in django
auth.usertable
./manage.py dumpdata auth.user > user.json
dumpdata (--exclude)
You can use
--excludeoption to specify apps/tables which don't need being dumpedFollowing command will dump the whole database with out including
auth.permissiontable content
./manage.py dumpdata --exclude auth.permission > db.json
dumpdata (--indent)
By default,
dumpdatawill output all data on a single line. It isn’t easy for humans to readYou can use the
--indentoption to pretty-print the output with a number of indentation spaces
./manage.py dumpdata auth.user --indent 2 > user.json
- Example output of above command is below

dumpdata (--format)
By default, dumpdata will format its output in JSON
You can specify the format using --format option
Command supports for following formats(serialization formats)
- json
- xml
- yaml
./manage.py dumpdata auth.user --indent 2 --format xml > user.xml
- Above command output an xml file(user.xml)

loaddata command
- This command can be use to load the fixtures(database dumps) into database
./manage.py loaddata user.json
- This command will add the
user.jsonfile content into the database
Restore fresh database
When you backup whole database by using
dumpdatacommand, it will backup all the database tablesIf you use this database dump to load the fresh database(in another django project), it can be causes
IntegrityError(If youloaddatain same database it works fine)To fix this problem, make sure to backup the database by excluding
contenttypesandauth.permissionstables
./manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json
- Now you can use
loaddatacommand with a fresh database
./manage.py loaddata db.json
Django使用manage.py备份与恢复数据的更多相关文章
- Django笔记 manage.py脚本的使用
1. 管理Django项目 python manage.py startproject projectname # 新建Django project ~~projectname是自己的项目名称 pyt ...
- python后台架构Django教程——manage.py命令
一.manage.py命令选项 manage.py是每个Django项目中自动生成的一个用于管理项目的脚本文件,需要通过python命令执行.manage.py接受的是Django提供的内置命令. 内 ...
- No module named _sqlite3 django python manage.py runserver
linux 执行django(python manage.py runserver),报错No module named _sqlite3,需要安装sqlite-devel,再重新编译安装python ...
- django python manage.py runserver 流程
python manage.py runserver 流程分析 版本 python27 django 1.0 搭建可运行的环境 创建python27 虚拟环境 github 下载 django-1.0 ...
- 关于django python manage.py startapp 应用名 出错异常原因
如题,在控制台运行python manage.py startapp sales 建立一个应用报错异常 1.应用名不能包含下划线等字符 所以app-demo 不能作为应用名被定义 2.manage.p ...
- Django中manage.py migrate无效的问题
在改变Django-model中结构后,makemigrations可以识别到改变但migrate没有操作,数据库中表结构也没有改变,原因如下: 在由Django-model自动生成的数据库表中有名为 ...
- Django manage.py 命令详解
manage.py 查看命令的作用的语句 C:\Users\Administrator> python manage.py help Type 'manage.py help <subco ...
- django orm 分页(paginator)取数据出现警告manage.py:1: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'sign.models.Guest'> QuerySet.
使用django的orm做分页(Paginator)时出现了下面的警告 In [19]: p=Paginator(guest_list,2) manage.py:1: UnorderedObjectL ...
- Django学习之manage.py使用
1.django-admin.py startproject mysite 开始一个项目,会初始化一些项目的结构文件 2.python manage.py runserver ip:port 如: p ...
随机推荐
- MoveIt运动规划-1
按照帮助文档Setup Assistant Tutorial中的描述,用moveit_setup_assistant图形界面一步步配置机器人,最后生成机器人的配置文件保存到指定的文件夹中. 以UR5机 ...
- SpringBoot之配置google kaptcha
项目中引入POM: <dependency> <groupId>com.google.code.kaptcha</groupId> <artifactId&g ...
- java 怎么实现接收控制台输入?
//接收键盘输入: //怎么实现接收控制台输入? import java.util.Scanner; //Test.java import java.util.Scanner; public clas ...
- error:No buffer space available (maximum connections reached
2015-02-02 17:49:09,035 ERROR basic.DBManager - Failded to establish the connection. com.mysql.jdbc. ...
- MongoDB安装实录
mongodb是nosql中的贵族,很受欢迎... 01.下载 官方:https://www.mongodb.com 社区版.企业版 https://www.mongodb.com/downloa ...
- servlet保存数据的几种方式
In Servlets you have 4 scopes where you can store data. Application Session Request Page
- Easyui入门视频教程 第03集---Easyui布局
Easyui入门视频教程 第03集---Easyui布局 目录 ----------------------- Easyui入门视频教程 第09集---登录完善 图标自定义 Easyui入门视频教 ...
- std::thread 不 join
std::thread 构造之后 使用 detach.就可以了
- python web中的并发请求
python web可以选择django,也可以选择flask,它们的原理差不多.flask比较轻量,下面写一段flask程序来说明python web对并发请求的处理. app.py import ...
- maven-compiler-plugin升级到3.1出现问题(转)
转自:http://my.oschina.net/zhuka/blog/124503 No compiler is provided in this environment. Perhaps you ...