如何使用 rake db:migrate 回滚一步

发布于 2024-10-06 04:20:58 字数 218 浏览 6 评论 0原文

db/migrate 文件夹中添加迁移文件并运行 rake db:migrate 后,我想回到上一步,我想使用 VERSION=n< /code> 是正确的方法,但我不知道要使用的 n 的正确值。有没有命令可以查看当前n值?

如果有人能够提供有关如何使用 rake db:migrate 的完整说明,那就太好了。

After adding migration files in the db/migrate folder and running rake db:migrate, I want get back to the previous step, I think using VERSION=n is the right way to do that, but I don't know the correct value of n to use. Is there any command to check the current n value?

It would be great if anyone could provide full instructions on how to use rake db:migrate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

同展鸳鸯锦 2024-10-13 04:20:58

对于初学者,

rake db:rollback 将使您后退一步

,然后

rake db:rollback STEP=n

将使您回滚 n 次迁移,其中 n 是您要回滚的最近迁移的数量。

更多参考此处

For starters

rake db:rollback will get you back one step

then

rake db:rollback STEP=n

Will roll you back n migrations where n is the number of recent migrations you want to rollback.

More references here.

弃爱 2024-10-13 04:20:58

回滚最近的迁移:

rake db:rollback

回滚 n 个最近的迁移:

rake db:rollback STEP=n

您可以在 Rails 运行迁移指南


还有更多内容:

  • rake db:migrate - 运行所有尚未运行的迁移
  • rake db:migrate VERSION=20080906120000 - 运行所有必要的迁移(向上或向下)获取给定版本
  • rake db:migrate RAILS_ENV=test - 在给定环境中运行迁移
  • rake db:migrate:redo - 回滚一个迁移并再次运行
  • < code>rake db:migrate:redo STEP=n - 回滚最后 n 次迁移并再次运行它们
  • rake db:migrate:up VERSION=20080906120000 -为给定的迁移运行 up 方法
  • rake db:migrate:down VERSION=20080906120000 - 为给定的迁移运行 down 方法

并回答关于从哪里获取迁移版本号的问题:

版本是迁移文件名的数字前缀。为了
例如,要迁移到版本 20080906120000 运行

$ rake db:migrate VERSION=20080906120000

(来自 Rails 指南中的 运行迁移

Roll back the most recent migration:

rake db:rollback

Roll back the n most recent migrations:

rake db:rollback STEP=n

You can find full instructions on the use of Rails migration tasks for rake on the Rails Guide for running migrations.


Here's some more:

  • 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

And to answer your question about where you get a migration's version number from:

The version is the numerical prefix on the migration's filename. For
example, to migrate to version 20080906120000 run

$ rake db:migrate VERSION=20080906120000

(From Running Migrations in the Rails Guides)

蹲在坟头点根烟 2024-10-13 04:20:58

最好的方法是使用 down 或 up 再次运行特定迁移(在 Rails 4 中。这是变化)

rails db:migrate:up VERSION=时间戳

现在如何获取时间戳。
走这条路

/db/迁移

确定要恢复的迁移文件。从该文件名中选择时间戳。

Best way is running Particular migration again by using down or up(in rails 4. It's change)

rails db:migrate:up VERSION=timestamp

Now how you get the timestamp.
Go to this path

/db/migrate

Identify migration file you want to revert.pick the timestamp from that file name.

伪心 2024-10-13 04:20:58

如果版本是 20150616132425,则使用:

rails db:migrate:down VERSION=20150616132425

If the version is 20150616132425, then use:

rails db:migrate:down VERSION=20150616132425
终难遇 2024-10-13 04:20:58

其他人已经回答了如何回滚,但您还问了如何识别迁移的版本号。

  • rake db:migrate:status 给出您的迁移版本、名称和状态(向上或向下)的列表
  • 您还可以找到迁移文件,其中文件名中包含时间戳,即版本号。迁移位于文件夹:/db/migrate

Other people have already answered you how to rollback, but you also asked how you could identify the version number of a migration.

  • rake db:migrate:status gives a list of your migrations version, name and status (up or down)
  • Your can also find the migration file, which contain a timestamp in the filename, that is the version number. Migrations are located in folder: /db/migrate
多情癖 2024-10-13 04:20:58
  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');
    }
  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');
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文