为什么需要将django迁移推送到版本控制系统

时间:2020-12-05 06:51:05

This is a common practice that people working on django project usually push migrations to the version control system along with other code.

这是一种常见的做法,即在django项目上工作的人通常会将迁移与其他代码一起推送到版本控制系统。

My question is why this practice is so common? Why not just push the updated models and everyone generate migrations locally. This approach can reduce the effort for resolving migrations conflicts too.

我的问题是为什么这种做法如此普遍?为什么不推送更新的模型,每个人都在本地生成迁移。这种方法也可以减少解决迁移冲突的工作量。

3 个解决方案

#1


5  

If you didn't commit them to a VCS then what would happen is people would make potentially conflicting changes to the model.

如果您没有将它们提交给VCS,那么会发生的情况是人们会对模型进行潜在的冲突更改。

When finally ready to deploy, you would still need django to make new migrations that would then merge everybodys changes together. And this just creates an additional unnecessary step that can introduce bugs.

当最终准备部署时,您仍然需要django进行新的迁移,然后将每个体系变化合并在一起。这只是创建了一个额外的不必要的步骤,可以引入错误。

You also are assuming everybody will always be able to work on an up to date version of the code which isn't always possible when you start working on branches that are not ready to be merged into mainline.

您还假设每个人都将能够处理代码的最新版本,当您开始处理尚未准备好合并到主线的分支时,这并不总是可行的。

#2


5  

Migrations synchronize the state of your database with the state of your code. If you don't check in the migrations into version control, you lose the intermediate steps. You won't be able to go back in the version control history and just run the code, as the database won't match the models at that point in time.

迁移会将数据库的状态与代码的状态同步。如果不将迁移签入到版本控制中,则会丢失中间步骤。您将无法返回版本控制历史记录并只运行代码,因为数据库与该时间点的模型不匹配。

Migrations, like any code, should be tested, at the very least on a basic level. Even though they are auto-generated, that's not a guarantee that they will work 100% of the time. So the safe path is to create the migrations in your development environment, test them, and then push them to the production environment to apply them there.

与任何代码一样,迁移应至少在基本级别上进行测试。尽管它们是自动生成的,但这并不能保证它们可以100%的时间工作。因此,安全的方法是在开发环境中创建迁移,测试它们,然后将它们推送到生产环境以在那里应用它们。

#3


2  

Firstly, migrations in version control allows you to run them in production.

首先,版本控制中的迁移允许您在生产中运行它们。

Secondly, migrations are not always automatically generated. For example, if you add a new field to a model, you might write a migration to populate the field. That migration cannot be re-created from the models. If that migration is not in version control, then no-one else will be able to run it.

其次,迁移并不总是自动生成。例如,如果向模型添加新字段,则可以编写迁移以填充该字段。无法从模型重新创建迁移。如果该迁移不在版本控制中,那么其他任何人都无法运行它。

#1


5  

If you didn't commit them to a VCS then what would happen is people would make potentially conflicting changes to the model.

如果您没有将它们提交给VCS,那么会发生的情况是人们会对模型进行潜在的冲突更改。

When finally ready to deploy, you would still need django to make new migrations that would then merge everybodys changes together. And this just creates an additional unnecessary step that can introduce bugs.

当最终准备部署时,您仍然需要django进行新的迁移,然后将每个体系变化合并在一起。这只是创建了一个额外的不必要的步骤,可以引入错误。

You also are assuming everybody will always be able to work on an up to date version of the code which isn't always possible when you start working on branches that are not ready to be merged into mainline.

您还假设每个人都将能够处理代码的最新版本,当您开始处理尚未准备好合并到主线的分支时,这并不总是可行的。

#2


5  

Migrations synchronize the state of your database with the state of your code. If you don't check in the migrations into version control, you lose the intermediate steps. You won't be able to go back in the version control history and just run the code, as the database won't match the models at that point in time.

迁移会将数据库的状态与代码的状态同步。如果不将迁移签入到版本控制中,则会丢失中间步骤。您将无法返回版本控制历史记录并只运行代码,因为数据库与该时间点的模型不匹配。

Migrations, like any code, should be tested, at the very least on a basic level. Even though they are auto-generated, that's not a guarantee that they will work 100% of the time. So the safe path is to create the migrations in your development environment, test them, and then push them to the production environment to apply them there.

与任何代码一样,迁移应至少在基本级别上进行测试。尽管它们是自动生成的,但这并不能保证它们可以100%的时间工作。因此,安全的方法是在开发环境中创建迁移,测试它们,然后将它们推送到生产环境以在那里应用它们。

#3


2  

Firstly, migrations in version control allows you to run them in production.

首先,版本控制中的迁移允许您在生产中运行它们。

Secondly, migrations are not always automatically generated. For example, if you add a new field to a model, you might write a migration to populate the field. That migration cannot be re-created from the models. If that migration is not in version control, then no-one else will be able to run it.

其次,迁移并不总是自动生成。例如,如果向模型添加新字段,则可以编写迁移以填充该字段。无法从模型重新创建迁移。如果该迁移不在版本控制中,那么其他任何人都无法运行它。