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 ...
随机推荐
- SpringBoot中mybatis配置自动转换驼峰标识没有生效
mybatis提供了一个配置: #开启驼峰命名转换 mybatis.configuration.map-underscore-to-camel-case=true 使用该配置可以让mybatis自动将 ...
- centos6.5官方dvd做本地yum
问题描述: 一切都搞定了,就是yum makecache 出现文件404,再目录看了也不对没后缀...(这不扯淡吗,rhel的dvd是可以直接使用的,难道企业版与社区版的区别??) 日志记录 [roo ...
- 存储过程—导出table数据为inser sqlt语句
Sql Server Management Studio没有将table中数据导出为insert语句的功能. 下面一个很有用的存储过程,可以把某张表的数据导出为insert sql语句.当然Oracl ...
- android官方资料
android develop – Guides http://developer.android.com/guide/ android develop – API Reference http:// ...
- android 用代码画虚线边框背景
1.虚线画效果,可以使用Android中的xml来做. 2.直接上代码: <RelativeLayout android:id="@+id/coupon_ ...
- ubuntu sublime 破解
1.去其官方网站http://www.sublimetext.com/ 把linux版下载下来,解开压缩包,放在你希望的路径下. 2.用vim将其打开 . vim sublime_text 3.将文件 ...
- HDU 1710 Binary Tree Traversals (二叉树遍历)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- php支付宝开发
1.下载对应的接口demo,注意退款有无密和有密 2.根据接口代码编写,要注意notify_url和return_url不能带有额外参数,并且notify_url中途不能含有跳转,否则post数据会丢 ...
- Android Studio每日小技巧
一般的什么快捷键,技巧的文章也有很多.我也看过很多.下面这些事我在来自国外大神发布的:Android Studio Tips of the Day查看到的,而且对于我来说有帮助的及没用过的. Andr ...
- hibernate使用注解设置日期默认值
用注解设置属性的默认值时 使用 @Temporal(TemporalType.TIMESTAMP) @Column(updatable = false,nullable=false,length=20 ...