Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heroku rake db:migrate > no such file to load -- faker

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
like image 566
David Tuite Avatar asked Feb 16 '11 07:02

David Tuite


3 Answers

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
like image 125
Simone Carletti Avatar answered Nov 02 '22 07:11

Simone Carletti


for me, Simone’s first approach didn’t work, but the second did: require 'faker' can be deleted from the rake file.

like image 30
törzsmókus Avatar answered Nov 02 '22 06:11

törzsmókus


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!

like image 1
Chris Avatar answered Nov 02 '22 07:11

Chris