简体   繁体   English

你如何在非主分支上干净地维护django迁移?

[英]How do you cleanly maintain django migrations on non-master branch?

  1. Imagine that I have a branch that has a migration. 想象一下,我有一个有迁移的分支。 It's an experimental branch that keeps up with master, but will not be merged into it for a while, if ever. 它是一个与主人保持联系的实验分支,但如果有的话,暂时不会合并到它。
  2. Master migrations change over time. 主迁移随着时间而变化。
  3. The result is that when I merge in master, I end up with multiple migration leaves, meaning that manage.py migrate errors out. 结果是,当我合并master时,我最终会有多个迁移离开,这意味着manage.py会将错误迁移出去。 If I just do manage.py makemigrations --merge , then it creates a new leaf that will later also be out of date. 如果我只是执行manage.py makemigrations --merge ,那么它会创建一个新的叶子,以后它也会过时。

Is there a nice way to handle this? 有一个很好的方法来处理这个? I'm tempted just to avoid having any migrations in long-lived dependent branches. 我很想避免在长期依赖的分支中进行任何迁移。

  1. Rebase an experimental branch on top of master before merging it. 在合并之前,在master上重新构建一个实验分支。
  2. Unapply all migrations from the experimental branch: 从实验分支中取消应用所有迁移:

     manage.py migrate <appname> <previousMigration> 
  3. Delete all migrations from the experimental branch. 从实验分支中删除所有迁移。

  4. Create a brand new migration: 创建全新的迁移:

     manage.py makemigrations 
  5. Commit changes to the experimental branch 提交对实验分支的更改

  6. Merge the experimental branch. 合并实验分支。

It's perfectly safe to delete migrations from a repository if no one else has applied them. 如果没有其他人应用迁移,那么从存储库中删除迁移是完全安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Django 1.7中重置应用程序的所有迁移? - How do you reset all migrations for an app in Django 1.7? 如何在 django 中动态迁移? - how to do migrations dynamically in django? 你如何解决 Django 中的 django.db.migrations.exceptions.NodeNotFoundError ? - How do you solve django.db.migrations.exceptions.NodeNotFoundError in Django? Django缺少迁移文件-如何将数据库与主文件同步? - Django missing migrations file - how to sync db with master file? 使用 Docker-Compose 时如何执行 Django 数据库迁移? - How do you perform Django database migrations when using Docker-Compose? 如何在 Dockerized Django 中运行迁移? - How do I run migrations in Dockerized Django? Django迁移:如何使现有模型抽象化? - Django migrations: How to make existing model non-abstract? 如何迁移类似于Ruby on Rails迁移的Django模型? - How can you migrate Django models similar to Ruby on Rails migrations? 错误:您正在尝试在Django迁移过程中向帐户添加非空字段“密码”,而没有默认设置 - Error: You are trying to add a non-nullable field 'password' to account without a default during Django migrations 当我在另一个分支上进行开发时,如何在master分支上本地运行Django服务器 - How to run Django server locally on master branch while I am developing on the other branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM