Run a single migration file

后端 未结 11 727
说谎
说谎 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 17:06

    If you want to run it from console, this is what you are looking for:

    $ rails console
    irb(main)> require "#{Rails.root.to_s}/db/migrate/XXXXX_my_migration.rb"
    irb(main)> AddFoo.migrate(:up)
    

    I tried the other answers, but requiring without Rails.root didnt work for me.

    Also, .migrate(:up) part forces the migration to rerun regardless if it has already run or not. This is useful for when you already ran a migration, have kinda undone it by messing around with the db and want a quick solution to have it up again.

提交回复
热议问题