简体   繁体   English

Django / Python-我应该在本地分支上运行makemigrations,还是仅在master上运行?

[英]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 makemigrationspython 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.

相关问题 当我在models.py中的python django中运行此命令python manage.py makemigrations博客时出错 - Error when I run this command python manage.py makemigrations blog in python django in models.py Python / Django makemigrations错误 - Python / Django makemigrations Error python-Django 本地服务器拒绝连接到管理页面 - python- Django local server refuses to connect to admin page django makemigrations:makemigrations 仅添加来自 model 的 id 字段 - django makemigrations: makemigrations add only id field from model Git Pycharm 仅将本地 master 分支更改为与 origin master 分支完全相同 - Git Pycharm change only the local master branch to be exactly like origin master branch 如果是travis-ci中的主分支,如何运行命令? - How to run a command only if is the master branch in travis-ci? Django中的Python社交认证,makemigrations检测不到任何变化 - Python social auth in Django, makemigrations detects no changes Python / Django项目中的命令错误makemigrations - Command error makemigrations in a Python/Django project python django - 从 makemigrations 中排除 class - python django - exclude class from makemigrations Django/Python 为 AppConfiguring 的 makemigrations 反馈 ImproperlyConfigured - Django/Python feeding back ImproperlyConfigured for makemigrations for AppConfiguring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM