I'm trying to deploy a rails 3 app to heroku for the first time. It seems to push up ok but when I try to run
heroku rake db:migrate
I get the following error:
rake aborted!
no such file to load -- faker
/app/98c71cc3-375f-4397-9de3-034dd7268be3/home/Rakefile:7
(See full trace by running task with --trace)
(in /app/98c71cc3-375f-4397-9de3-034dd7268be3/home)
Here's my rakefile (line 7 is the last one):
require File.expand_path('../config/application', __FILE__)
require 'rake'
SampleApp::Application.load_tasks
Now I have a task called sample_data.rake which uses the faker gem to populate the development database with sample data and that task has the line:
require 'faker'
at the top which must be what's causing the problem.
How can I fix this error or is there a way that I can get heroku to ignore this task file? I'm not going to want to populate the production version with nonsense sample data anyway.
By the way, faker is only active in the development environment in my gemsfile:
# gemfiles for the rspec testing environment
group :development do
gem 'rspec-rails', '2.5.0'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.3.1'
end
Move the require statement into the task. For instance
# sample_data.rake
require 'faker'
task :sample_data => :environment do
# ...
end
to
# sample_data.rake
task :sample_data => :environment do
require 'faker'
# ...
end
In this way, the library will be required only when the task is invoked.
The other alternative is to not require Faker in your rake file. In fact, it is already loaded by Bundler when the bundle is executed in development.
If you don't want Bundler to load the Gem, use
gem 'faker', '0.3.1', :require => false
for me, Simone’s first approach didn’t work, but the second did: require 'faker'
can be deleted from the rake file.
I too commented out require 'faker' in the lib/tasks/sample_data.rake file and (After committing this change via git) pushed the files to heroku, which allowed
$heroku rake db:migrate --app <my app name>
to successfully execute, and ergo the heorku site began working again.
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With