DEV Community

Discussion on: Rails Migration Hacks !! Things You should know if you are a ROR Developer .

Collapse
 
sambitmohanty954 profile image
Sambit Mohanty • Edited

in api.rubyonrails.org/classes/Active... website written:-

"Some transformations are destructive in a manner that cannot be reversed. Migrations of that kind should raise an ActiveRecord::IrreversibleMigration exception in their down method."

But there is way you can reverse it????

you can reverse it by using "Reversible" , basically this method allow you to specify up and down behavior for part of the migration. so in Reversible part you can write your your own method

class MigartionFileName < ActiveRecord::Migration[6.0]
  def change

    reversible do |var|
      var.up do
        --------your up method------
      end

      var.down do
       -------your down method-----
      end

    end
  end
end

thanks for your comment , stay tuned for more interesting topic . if you want something that i cover on my ruby on rails blog then please do let me know . _^

Some comments have been hidden by the post's author - find out more