Rails 迁移 - 寻找旧迁移中的变化?
如果我有两个迁移,mig1 和 mig2,我运行 rake db:migrate,然后返回 mig1 并更改列的默认值,当我再次运行 rake db:migrate 时,此更改是否会反映出来?或者我是否必须仅为该列进行新的迁移才能进行更改?
If I have two migrations, mig1 and mig2, I run rake db:migrate, then I go back to mig1 and change the default value of a column, will this change be reflected when I run rake db:migrate again? Or do I have to make a new migration just for that column to make the change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过运行以下命令重做给定的版本:
You can redo a given VERSION by running the following:
您应该进行新的迁移,或者使用 rake
db:rollback
任务移回到运行相关迁移之前的数据库版本。对迁移脚本的更改不会自动生效。架构的当前版本会被跟踪并应用于迁移,因此运行 rake db:migrate 不会重新运行旧的迁移。正是由于这个原因,只要您在迁移时提供了正确的
self.down
方法,您就可以使用rollback
功能。回滚会执行这些向下方法,同时撤消迁移。然后,您可以编辑迁移并重新迁移。
You should either make a new migration or use the rake
db:rollback
task to move back to the version of your database before the migration in question was ran. Changes to migration scripts won't be automatically picked up.The current version of your schema is tracked and applied to migrations, so running rake db:migrate will not rerun old migrations. It is for this reason that you are able to use the
rollback
feature, as long as you provided correctself.down
methods on your migration. Rolling back executes these down methods, undoing the migrations as it goes.You can then edit the migration and re-migrate.
rake db:migrate:redo VERSION=____
rake db:migrate:redo VERSION=____