如何压缩最近的Django迁移? [英] How to squash recent Django migrations?
问题描述
在Django的迁移代码中,有一个 squashmigrations
命令:将$ code> app_label 的迁移最大化并包括如果可能的话, migration_name
减少迁移。
所以,如果你想挤压,说,第一个5个迁移,这将有所帮助。
从特定的 migration_name
开始,最好的方法是什么? >
在我正在开展的项目中,我们添加了5-10个新的迁移文件,因为我们添加了新功能。我们将立即部署整个项目,看起来单独运行这些项目将需要太长时间。我想将这个项目的所有迁移压缩成一个单一的迁移,并测试运行时间。
python manage.py squashmigrations< appname> < squashfrom> < squashto>
python manage.py help squashmigrations
https://docs.djangoproject.com/en/dev/topics/migrations/#migration-squashing
这将使您更精细地控制哪些迁移到壁球,并让您保持更清晰的提交历史记录。删除+重新创建所有迁移可能会导致其他问题,例如循环依赖,具体取决于模型的构造方式。
In Django's migrations code, there's a squashmigrations
command which: "Squashes the migrations for app_label
up to and including migration_name
down into fewer migrations, if possible."
So, if you want to squash, say, the first 5 migrations, this will help.
What's the best way to squash starting with a particular migration_name
?
In a project I'm currently working on, we've added 5-10 new migration files as we've added new features. We'll deploy the whole project at once and it looks like running these individually will take too long. I'd like to squash all the migrations for this project into a single migration and test the time to run that.
python manage.py squashmigrations <appname> <squashfrom> <squashto>
python manage.py help squashmigrations
https://docs.djangoproject.com/en/dev/topics/migrations/#migration-squashing
This will give you more granular control over which migrations to squash, and let you keep a cleaner commit history. Deleting + recreating all migrations may cause other issues such as circular dependencies depending on how models are constructed.
这篇关于如何压缩最近的Django迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!