[英]Django/ Python- should I run makemigrations on a local branch, or only on master?
I am working on a project that has been written in Python/ Django, and have recently made some changes to one of the models
. 我正在开发一个用Python / Django编写的项目,最近对其中一个models
进行了一些更改。 I want to test the changes that I have made now, before I go any further into the development of this new feature, but I am aware that I will need to run python manage.py makemigrations
& python manage.py migrate
before the changes that I have made to the models
take effect. 在继续开发此新功能之前,我想测试一下我现在所做的更改,但是我知道在更改之前,我需要先运行python manage.py makemigrations
和python manage.py migrate
python manage.py makemigrations
。我已经使models
生效。
I am doing the development on a separate git
branch to master
, but am a bit unsure what the best practice is here in terms of running migrations on different branches (I am relatively new to both Python/ Django & Git). 我正在一个单独的git
分支上进行开发以master
,但是有点不确定在不同分支上运行迁移方面的最佳实践是什么(我对Python / Django和Git都是比较陌生的)。
Would it be sensible to run makemigrations
on my development branch, and testing it there, the same way I have been testing the bug fixes that I have worked on so far, or will I need to merge my development branch with master
before running makemigrations
? 在我的开发分支上运行makemigrations
并在makemigrations
进行测试是否明智, makemigrations
我测试到目前为止所研究的错误修复程序一样,还是在运行makemigrations
之前需要将开发分支与master
合并?
I know that if I do run the migrations on my development branch, I will need to run them again on master
once I have merged my changes, but I was just wondering if there are any dangers to this approach, or things I should look out for? 我知道,如果我确实在我的开发分支上运行迁移,那么一旦合并更改,就需要在master
再次运行它们,但是我只是想知道这种方法是否存在任何危险,或者应该注意的事情对于?
Generally, you would do a makemigrations on your development branch, and you would move the code (in this case, migration files) up to higher branches (UAT, Staging, Master etc). 通常,您将在开发分支上进行makemigrations,并将代码(在这种情况下为迁移文件)上移到更高的分支(UAT,Staging,Master等)。
This way you would never need to run makemigrations on any other branch, but only the migrate command. 这样,您将不需要在任何其他分支上运行makemigrations,而仅需要migrate命令。
You can have as many migration files as you need, it doesn't really affect performance and is highly optimised 您可以根据需要拥有任意数量的迁移文件,它不会真正影响性能,并且经过高度优化
You can always squash/merge your migrations if there are too many or if you wish to do so. 如果迁移过多或希望迁移,可以始终压缩/合并迁移。
See Squasing Migrations 请参见压缩迁移
Running makemigrations
will automatically create python files in the "migrations" folder of the app where you modified the model. 运行makemigrations
将在修改模型的应用程序的“ migrations”文件夹中自动创建python文件。 These files must be versionned in git because they cannot be dissociated from your modifications of the model. 这些文件必须在git中进行版本控制,因为它们无法与您对模型的修改脱离。
Then, when you will merge your branch, both the modification in the model and the corresponding migration will be in the git tree. 然后,当您合并分支时,模型中的修改和相应的迁移都将在git树中。 So the next call to migrate
will synchronize the DB with the current state described by your models. 因此,下一个migrate
请求将使数据库与模型描述的当前状态同步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.