heroku run rake db:migrate ... rake aborted! No Rakefile found - ruby-on-rails

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

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

Related

Rake -T does not identify tasks

I am trying to setup a Rake Task (without rails), and thus created a demo Hello World Task. However, upon running rake -T or rake --tasks nothing is returned, as if the task hasn't been identified. What am I doing wrong here?
Also When I run rake hello_world I get the following error:
➜ ~/GitHub/Cerner/test git:(master) ✗ rake hello_world
rake aborted!
Don't know how to build task 'hello_world' (See the list of available tasks with `rake --tasks`)
/usr/share/rvm/gems/ruby-2.6.6/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `eval'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)
[Update] The rakefile:
# frozen_string_literal: true
# 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.
$LOAD_PATH.push File.expand_path('lib', __dir__)

rake db:create showing error on rake db:create

I am trying to connect to mysql and using command rake db:create
. It is showing me error
rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /Library/Ruby/Gems/2.0.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>' (See full trace by running task with --trace)
I also tried rake db:migrate as well but same error.
It looks like your missing a rake file. Add this code in a file called Rakefile at the root of your app.
Edit: Replace YourApp by the name of your app
require File.expand_path('../config/application', __FILE__)
YourApp::Application.load_tasks

rake:db seed issue with Catarse

I'm trying to clone the Catarse repository: Git catarse
and I get all the way to the end but once I try to run rake db:seed I get the following error message:
rake aborted!
Errno::ENOENT: No such file or directory # dir_initialize - /Users/'USERNAME'/Desktop/my_websites/crowdfund_test/catarse/tmp/cache/
/Users/'USERNAME'/Desktop/my_websites/crowdfund_test/catarse/db/seeds.rb:116:in `<top (required)>'
Tasks: TOP => db:seed
Do you know why??
I was having the same problem. Then I realized I did not have the directory
/yourPath/catarse/tmp/cache/
Once I created it, seeding worked just fine!

Rake db:seed fails with 'don't know how to build task db.seed'

I get the following error when I run rake db.seed, how can I fix it?
(I tried deleting seed.rb and recreating it, but it didn't work)
rake aborted! Don't know how to build task 'db.seed'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task_manager.rb:62:in
[]'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:149:in
invoke_task'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
block (2 levels) in top_level'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
each'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in
block in top_level'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in
run_with_threads'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in
top_level'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in
block in run'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in
standard_exception_handling'
/Users/user/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in
run' /Users/user/.rbenv/versions/2.2.1/bin/rake:33:in `
Background information:
I am following a tutorial in which I have created a mock user in my db.seed file.
User.create! email: 'test#test.com', password: 'password',
password_confirmation: 'password'
Now when I run the command rake db:seed, I get the error above. How can I successfully run the command?
To avoid such errors in future, what you could do is, type bundle exec rake -T from the project directory to list all the available rake tasks for your Rails app:
➜ bundle exec rake -T
rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databa...
rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in...
rake db:fixtures:load # Load fixtures into the current environment's database
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:cache:clear # Clear a db/schema_cache.dump file
rake db:schema:cache:dump # Create a db/schema_cache.dump file
rake db:schema:dump # Create a db/schema.rb file that is portable against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
Then, just copy the task that you are looking for (rake db:seed in this case) and run the rake task!

Rails seed file not loading for me in production profile after 3.16 and capistrano 3.1 upgrade

I have an app that I have been in happily developing for some time, and haven't had any trouble seeding the production database with my seed file until recently, as I have been attempting to get capistrano deployment working, which spawned an upgrade and gem dependency exercise;-first I blamed capistrano but this behavior happens locally.
So if I reset and seed with:
RAILS_ENV=production rake db:reset
and I end up with tables being undefined that the seed file is attempting to load: e.g:
...tables being built:
.
.
.
-- initialize_schema_migrations_table()
-> 0.0037s
-- assume_migrated_upto_version(20140117153600, ["/Users/jaytho/Projects/1.1.1-a1.dev.merge_test/db/migrate"])
-> 0.0020s
BankCards
rake aborted!
uninitialized constant BankCard
/Users/jaytho/Projects/1.1.1-a1.dev.merge_test/db/seeds.rb:7:in block (2 levels) in <top (required)>'
/Users/jaytho/Projects/1.1.1-a1.dev.merge_test/db/seeds.rb:6:inblock in '
/Users/jaytho/Projects/1.1.1-a1.dev.merge_test/db/seeds.rb:4:in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.16/lib/rails/engine.rb:525:inload'
/usr/local/rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.16/lib/rails/engine.rb:525:in load_seed'
/usr/local/rvm/gems/ruby-1.9.3-p448#global/gems/activerecord-3.2.16/lib/active_record/railties/databases.rake:347:inblock (2 levels) in '
/usr/local/rvm/gems/ruby-1.9.3-p448#global/gems/activerecord-3.2.16/lib/active_record/railties/databases.rake:290:in `block (2 levels) in '
Tasks: TOP => db:setup => db:seed
(See full trace by running task with –trace)
of which BankCard is the first table seeds.rb is attempting to populate. Comment out BankCard and it just goes to the next table.
The db:reset command works perfectly with in the other environments:
RAILS_ENV=development rake db:reset
and
RAILS_ENV=test rake db:reset
a downgrade to 3.2.15 did not help. I also attempted many permutations like:
bundle exec rake db:reset RAILS_ENV=production
RAILS_ENV=production bundle exec rake db:drop db:create db:migrate db:seed
and I even wiped all my migrations and tried just from the schema thinking that a mangled migration silently causing an issue:
RAILS_ENV=production bundle exec rake db:schema:load db:seed
without any luck- exact same answer.
I also attempted to extract the seed.rb routines into a separate rake task- same result.
The brain twister for me is that if I call the seeds.rb from the console:
'echo load “db/seeds.rb”' | RAILS_ENV=production rails c
she loads without any issues. It works from the console.
I attempted to get into databases.rake and try and recreate the environment there to duplicate the environment into my own rakefile; however, since calls into databases.rake exhibit the same problem, I am pretty much stuck between a rock and a hard place.
What can I be doing wrong to pollute only the production environment? How can I debug this?
Thanks in advance. Beer is on me if you ever are in Dallas.
After some insomnia and some more varied google searches I stumbled on this website: http://community.activestate.com/node/9065 and
Rails 3.2.11 asset precompile fails if threadsafe! enabled where they give clues that threadsafe is important.
Sure enough; if I comment out the threadsafe line in config/environments/production.rb:
# Enable threaded mode
# config.threadsafe!
My rake db:seed tasks work in production.
the solutions in those articles, for some reason didn't work. I ended up doing this to fix it in config/environments/production.rb
# Enable threaded mode
config.threadsafe! unless $rails_rake_task
I hope this helps somebody else out who is upgrading.

Resources