Django选择性Dumpdata

编程入门 行业动态 更新时间:2024-10-12 12:31:24
本文介绍了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

本文发布于:2023-10-27 10:43:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选择性   Django   Dumpdata

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!