Search code examples
ruby-on-railsherokurakeabortrakefile

heroku run rake db:migrate ... rake aborted! No Rakefile found


When I run heroku run rake db:migrate, I receive the following error:

$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.8507
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/lib/ruby/1.9.1/rake.rb:2367:in `raw_load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/local/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/local/bin/rake:31:in `<main>'

Other users have posted identical errors, but in their case they actually didn't have a Rakefile and it worked for them once they created one, or they were in the wrong directory. My app does have a Rakefile, in the correct directory and with all the proper text in it, and I am in my app's root directory.

This is what my Rakefile looks like:

    # Add your own tasks in files placed in lib/tasks ending in .rake,
    # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

    require File.expand_path('../config/application', __FILE__)

    Rails.application.load_tasks

This is what "heroku run cat Rakefile" does:

    $ heroku run cat Rakefile
    Running `cat Rakefile` attached to terminal... up, run.9132
    cat: Rakefile: No such file or directory

Solution

  • Whenever you are struggling with Heroku you should check your logs:

    heroku logs
    

    Scan through for any errors that you can google and/or get hints to what is going wrong.

    If you are using git you can quickly search for errors with this:

    git grep "whatever you want to search for"
    

    You will then know where to find the file so you might try to verify that the rakefile actually exists with:

    git grep rakefile
    

    Sometimes it is easier to just start fresh and reset your database and reload your current schema with:

    rake db:reset db:migrate all
    

    This will destroy your db and then create it and then migrate your current schema:

    rake db:drop db:create db:migrate 
    

    If you want to reset the heroku db

    To drop the database, if you are using SHARED_DATABASE_URL:

    heroku pg:reset DATABASE
    

    To recreate the database with nothing in it:

    heroku run rake db:migrate
    

    To populate the database with your seed data:

    heroku run rake db:seed