如果我创建一个表 rails generate migration
,我可以稍后通过创建新的迁移添加一个额外的列。我还可以回滚原始迁移,然后编辑它以包含额外的列。
方法1:新迁移
//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
方法2:回滚
//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
完成此任务的正确/最佳方法是什么?为什么?