在db/migrate文件夹中添加迁移文件并运行rake db:migrate后,我想回到前面的步骤,我认为使用VERSION=n是正确的方法,但我不知道n的正确值。是否有命令可以检查当前n的值?
如果有人能提供关于如何使用rake db:migrate的完整说明,那就太好了。
在db/migrate文件夹中添加迁移文件并运行rake db:migrate后,我想回到前面的步骤,我认为使用VERSION=n是正确的方法,但我不知道n的正确值。是否有命令可以检查当前n的值?
如果有人能提供关于如何使用rake db:migrate的完整说明,那就太好了。
对于初学者来说
回滚会让你后退一步
然后
rake db:rollback STEP=n
将回滚n个迁移,其中n是您想要回滚的最近迁移的数量。
这里有更多参考资料。
回滚最近的迁移:
rake db:rollback
回滚最近的n次迁移:
rake db:rollback STEP=n
您可以在运行迁移的Rails指南中找到关于使用rake的Rails迁移任务的完整说明。
这里还有一些:
rake db:migrate - Run all migrations that haven't been run already rake db:migrate VERSION=20080906120000 - Run all necessary migrations (up or down) to get to the given version rake db:migrate RAILS_ENV=test - Run migrations in the given environment rake db:migrate:redo - Roll back one migration and run it again rake db:migrate:redo STEP=n - Roll back the last n migrations and run them again rake db:migrate:up VERSION=20080906120000 - Run the up method for the given migration rake db:migrate:down VERSION=20080906120000 - Run the down method for the given migration
为了回答您关于从哪里获得迁移版本号的问题:
版本是迁移文件名上的数字前缀。为 例如,迁移到版本20080906120000运行 $ rake db:migrate VERSION=20080906120000
(来自在Rails指南中运行迁移)
最好的方法是再次使用down或up(在rails 4中)运行特殊迁移。它的改变)
rails db:migrate:up版本=时间戳
现在你如何得到时间戳。 走这条路
/db/migrate
确定要还原的迁移文件。从该文件名中选择时间戳。
其他人已经回答了如何回滚,但是您还询问了如何识别迁移的版本号。
status给出了您的迁移版本、名称和状态(向上或向下)的列表。 您还可以找到迁移文件,该文件在文件名中包含时间戳,即版本号。迁移位于文件夹:/db/migrate中
try {
$result=DB::table('users')->whereExists(function ($Query){
$Query->where('id','<','14162756');
$Query->whereBetween('password',[14162756,48384486]);
$Query->whereIn('id',[3,8,12]);
});
}catch (\Exception $error){
Log::error($error);
DB::rollBack(1);
return redirect()->route('bye');
}