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 ...
随机推荐
- Android开发之欢迎界面标准
import java.util.ArrayList; import android.app.Activity; import android.content.SharedPreferences; i ...
- 【物联网智能网关-17】.NET Micro Framework之MDK C++二次开发
.NET Micro Framework虽然好学易用,但是在一些需要实时,需要高性能的应用领域,却有些勉为其难.毕竟.NET Micro Framework上层应用程序由底层CLR(TinyCLR)解 ...
- 怎样查看SSL证书的有效期?自动续期是否生效?
前面一篇教程教大家如何能够把网站的 HTTPS 的 SSL 证书自动续期.料神米课的学员动手能力都很强,已经很多都成功把证书续期了.但怎么看证书续期是否成功了呢? 使用火狐 firefox 浏览器就可 ...
- ios中键盘处理(二)
设置UIscrollview的背景代码 - (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame { UIGraphic ...
- <转>LUA语法分析
本文选自:http://www.cnblogs.com/nazhizq/p/6516561.html 一步步调试,在lparser.c文件中luaY_parser函数是语法分析的重点函数,词法分析也是 ...
- MySQL备份与还原详细过程示例
MySQL备份与还原详细过程示例 一.MySQL备份类型 1.热备份.温备份.冷备份 (根据服务器状态) 热备份:读.写不受影响: 温备份:仅可以执行读操作: 冷备份:离线备份:读.写操作均中止: 2 ...
- MySQL的初次见面礼基础实战篇
[版权申明] http://blog.csdn.net/javazejian/article/details/61614366 出自[zejian的博客] 关联文章: MySQL的初次见面礼基础实战篇 ...
- wxml
<template name="objectCombine"> <view> <text> {{for}} </text> < ...
- Snip for Mac(桌面截图工具)安装
1.软件简介 Snip 一款用于桌面截图的工具. 2.资源列表 链接 提取密码 系统要求 软件语言 Snip for Mac v2.0 (5771) fgab macOS 10.6.8 及以上 ...
- SQL Server中临时表与表变量的区别
我们在数据库中使用表的时候,经常会遇到两种使用表的方法,分别就是使用临时表及表变量.在实际使用的时候,我们如何灵活的在存储过程中运用它们,虽然它们实现的功能基本上是一样的,可如何在一个存储过程中有时候 ...