Django选择性Dumpdata [英] Django Selective Dumpdata

查看:219
本文介绍了Django选择性Dumpdata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以选择性地过滤Django的dumpdata管理命令输出的记录?我有几个模型,每个都有数百万行,我只想在一个模型中转储记录,符合特定条件,以及引用任何这些记录的所有外键链接记录。

Is it possible to selectively filter which records Django's dumpdata management command outputs? I have a few models, each with millions of rows, and I only want to dump records in one model fitting a specific criteria, as well as all foreign-key linked records referencing any of those records.

考虑这个用例。说我有一个生产数据库,我的用户模型有数百万条记录。我有几个其他模型(日志,交易,购买,书签等)都引用了用户模型。我想在我的Django应用程序上进行开发,我想使用逼真的数据进行测试。然而,我的生产数据库是如此巨大,我不能真实地拍摄整个事情的快照,并在本地加载它。所以理想情况下,我想使用dumpdata将50个随机用户记录和所有相关的记录转储给JSON,并使用它来填充开发数据库。

Consider this use-case. Say I had a production database where my User model has millions of records. I have several other models (Log, Transaction, Purchase, Bookmarks, etc) all referencing the User model. I want to do development on my Django app, and I want to test using realistic data. However, my production database is so enormous, I can't realistically take a snapshot of the entire thing and load it locally. So ideally, I'd want to use dumpdata to dump 50 random User records, and all related records to JSON, and use that to populate a development database.

是否存在一个简单的方法来实现这一点?

Is there an easy way to accomplish this?

推荐答案

我认为 django-fixture-magic 可能值得一看。

您会发现一些额外的背景信息在清理Django数据库

You'll find some additional background info in Scrubbing your Django database.

这篇关于Django选择性Dumpdata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆