Django 迁移最佳实践

Django migrations best practice

我正在使用带有迁移的 Django 1.7,我不确定什么是最佳实践,我应该将迁移文件添加到我的存储库,或者这是一个坏主意?

您应该在本地创建迁移文件,在本地迁移并测试它,然后将文件提交到版本控制。 django 文档说:

The reason that there are separate commands to make and apply migrations is because you’ll commit migrations to your version control system and ship them with your app; they not only make your development easier, they’re also useable by other developers and in production.

如果多个开发人员在同一个项目上工作,他们不必创建迁移文件,他们只需要 migrate,一切都是天堂。

是的,它们必须进行版本控制。如果您是一个人,这不是问题,因为您添加了正确的数据库模式,因为每次编辑模型时,您 运行 makemigrationsmigrate

但是如果您的同事也不能 运行 您的迁移,他们如何拥有与您提交的新模型相对应的数据库架构。

提交您的迁移,让您的同事 运行 migrate 拥有相同的数据库架构。