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!
Related
I reset the database on Heroku in the database setting and ran heroku run rake db:migrate. Although it created all the data tables with correct columns per local database, it does not migrate any existing local data. Heroku database is just empty. In the past I ran the above code and worked fine but this time got stuck as shown below:
mac-a:skiny ran$ heroku run bundle exec rake db:migrate
Running bundle exec rake db:migrate on ⬢ blooming-citadel-66205... up, run.3076 (Hobby)
The PGconn, PGresult, and PGError constants are deprecated, and will be
removed as of version 1.0.
You should use PG::Connection, PG::Result, and PG::Error instead, respectively.
Called from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
ActiveRecord::SchemaMigration Load (1.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
As a note, I quit mac terminal while running heroku run rake db:reset and maybe there is some internal error...
Try to the following, edit your Gemfile like below
gem 'pg', '~> 0.20.0'
Or
gem 'pg', '~> 0.11'
Then bundle install and try, it's working on my hand.
Note: the tilde sign before the >, that's not a dash
Once you make this update in your group production of your Gemfile, ensure you run bundle install --without production (to update Gemfile.lock file), do a git add/commit cycle, then re-deploy to Heroku.
Hope it helps
Migrations are not supposed to create data. They define tables, indexes, constraints, etc.
You should use db:seed, after migrating, to create data (besides adding pg version as mentioned on other answer.)
I am using pg for dev and test in local machine only
its in dev and test group out in gemfile
group :development, :test do
gem 'pg'
end
rails version is
Rails 3.0.19
ruby 1.8.7
I used moonshine or shorter cut of capistrano
capistrano:deploy
the migrations file can't be migrated using capistrano, throws an error.
I am trying to run migrations manually inside server
bundle exec rake db:migrate VERSION=20140205173759_add_hebrew_to_piles.rb
I have three files and wanted to run rake migrate on each one (got it from stackoverlow, rails run specific migration)
and got
no such file to load -- pg
I am using mysql as production database so I don't understand why is looking for pg inside my server? any help?
I'm quite new to ruby and ruby on rails and I'm trying to add Cucumber to my new rails 3 application.
My Gemfile contains this section:
group :test, :development do
gem 'rspec-rails', '~>2.5'
end
group :test do
# Pretty printed test output
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
end
To install Cucumber first I've run:
bundle install --binstubs
and after all my gems are installed I've run:
rails generate cucumber:install --rspec --capybara
My problem is that during installation of cucumber those changes are made:
create config/cucumber.yml
create script/cucumber
chmod script/cucumber
create features/step_definitions
create features/support
create features/support/env.rb
exist lib/tasks
create lib/tasks/cucumber.rake
gsub config/database.yml
gsub config/database.yml
force config/database.yml
but as I understand more files should be created (some helpers file) - like this:
create config/cucumber.yml
create script/cucumber
chmod script/cucumber
create features/step_definitions
create features/step_definitions/web_steps.rb
create features/support
create features/support/paths.rb
create features/support/selectors.rb
create features/support/env.rb
exist lib/tasks
create lib/tasks/cucumber.rake
gsub config/database.yml
gsub config/database.yml
force config/database.yml
Could somebody tell me what am I doing wrong?
Thanks in advance!
After some searching in the internet I'm able to answer to this question by myself ;)
It turned out that everything is ok with this Cucumber installation. Currently there is a change in 'cucumber-rails' gem and web_steps.rb (and others) file isn't generated anymore. About the reason you can read here: 'The training wheels came off'
The problem has occurred because I learn Ruby on Rails from "Rails 3 in Action" book in which old behavior of 'cucumber-rails' gem is described.
Ruby 1.9.2 Rails 3.1
After the day of fighting with heroku issues I was able to finally have the command 'git push heroku master to work properly'.
Gemfile has proper enties and pg gem is installed
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
At this point application has been uploaded and start page can be viewed here http://growing-day-7939.heroku.com/
The next step should be migrating the database to the heroku with 'heroku rake db:migrate"
and it always fails.
c:\RailsInstaller\work\rfclub>heroku rake db:migrate
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
Other heroku commands fail with the same error as above - heroku ps, heroku logs, heroku config.
I've tried deleting and recreating the app, even tried creating the new heroku account and repeating the steps, but nothing seems to help.
Any ideas would be appreciated, I'm really stuck.
I think you'll need to deploy Rails 3.1 apps on Heroku's Cedar stack, via heroku create --stack cedar. The migration command will be heroku run rake db:migrate.
Im not going to start by saying i'm a newbie etc. Jokes, been learning Rails for nearly month using Lynda.com. I use Mac, Mac OS X Lion 10.7.
I am trying to intall Paperclip Gem but i can't seem to figure out what i'm doing wrong.
I followed the instructions on https://github.com/thoughtbot/paperclip/wiki/Installation
I added this line to my config/environment.rb
config.gem 'paperclip', :source => 'http://rubygems.org'
and i then tried to run
rake gems:install
I get an error message:
(in /Users/fred/Ruby/food)
rake aborted!
undefined local variable or method `config' for main:Object
/Users/fred/Ruby/food/Rakefile:4:in `require'
(See full trace by running task with --trace)
I then tried the following as an alternative when the above failed
script/plugin install git://github.com/thoughtbot/paperclip
I get the following error
-bash: script/plugin: No such file or directory
My question is how do install this gem? I have read a lot of other posts that say i should include gem 'paperclip', "~> 2.3" is this the same as what i did above?
Best to use bundler. Steps are
Install bundler: gem install bundler
Add to Gemfile: config.gem 'paperclip'
cd to where the Gemfile is and run: bundle install. This will install all the gems mentioned in the Gemfile
Ps. I assume that you are not using rvm. Also, you may need to prefix sudo to the command in step 1 above in case the command does not work for you due to a permission problem.