Search code examples
rubyruby-on-rails-4

how to run rake db:migrate on irb


I am trying to run a migration script on irb but it returns syntax error.

irb(main):008:0> rake db:migrate:up VERSION=20171006190045
SyntaxError: (irb):8: syntax error, unexpected tLABEL
rake db:migrate:up VERSION=20171006190045

tried rake db:migrate:redo VERSION=20171006190045

Also tried this

irb(main):012:0> require 'db/migrate/20171006190045_update_details.rb'
LoadError: cannot load such file -- db/migrate/20171006190045_update_details.rb
    from (irb):12

Solution

  • rake is not meant to be run within IRB. I agree with @spickermann. You can run it in rails console by using system command.

    $ rails c
    > system("rake db:migrate:up VERSION=20171006190045")
    

    or simply in terminal

    $ rake db:migrate:up VERSION=20171006190045