如果我创建一个包含rails generate migration
的表,我可以稍后通过创建新的迁移为其添加一个额外的列。我还可以回滚原始迁移,然后对其进行编辑以包含额外的列。
//Create the model including the migration
$ rails generate model Foo bar:string
//Perform the migration
$ rake db:migrate
//Create the add column migration
$ rails generate migration add_foobar_to_foos foobar:string
//Perform the new migration
$ rake db:migrate
//Create the model including the migration
$ rails generate model Foo bar:string
//Perform the migration
$ rake db:migrate
//Rollback the migration
$ rake db:rollback
//Edit the original migration file
//Perform the new migration
$ rake db:migrate
完成此任务的正确/最佳方法是什么?为什么?
答案 0 :(得分:13)
我想方法1.为什么?因为如果其他开发人员/机器正在使用此环境,您可能会因为他们可能需要在正确的时间回滚以维持正确的数据库结构而获得不稳定的状态。