Ruby on Rails:如何使用rake db:migrate还原迁移? [英] Ruby on Rails: How can I revert a migration with rake db:migrate?

查看:68
本文介绍了Ruby on Rails:如何使用rake db:migrate还原迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装了devise MODEL User之后,我明白了.

After installing devise MODEL User i got this.

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

现在,如果我使用db:migrate命令,将创建users表.

Now if i do rake db:migrate the users table will be created.

如何还原此迁移,即如何再次使用rake删除users表?

How can i revert this migration, i.e. how can I delete the users table using rake again ?

推荐答案

运行以下命令

rake db:migrate:down VERSION=<version>

其中<version>是要还原的迁移文件的版本号.

where <version> is the version number of your migration file you want to revert.

例如如果要还原文件名为3846656238_create_users.rb的迁移

eg. if you want to revert a migration with file name 3846656238_create_users.rb

rake db:migrate:down VERSION = 3846656238

rake db:migrate:down VERSION=3846656238

这篇关于Ruby on Rails:如何使用rake db:migrate还原迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆