Run a single migration file

后端 未结 11 745
说谎
说谎 2020-11-30 16:01

Is there an easy way to run a single migration? I don\'t want to migrate to a certain version I just want to run a specific one.

11条回答
  •  臣服心动
    2020-11-30 16:51

    This are the steps to run again this migration file "20150927161307_create_users.rb"

    1. Run the console mode. (rails c)
    2. Copy and past the class which is in that file to the console.

      class CreateUsers < ActiveRecord::Migration
        def change
          create_table :users do |t|
            t.string :name
            t.string :email
            t.timestamps null: false   end
          end
        end
      end
      
    3. Create an instance of the class CreateUsers: c1 = CreateUsers.new

    4. Execute the method change of that instance: c1.change

提交回复
热议问题