Cant run db:migrate - ruby-on-rails

I trying to deploy my rails 4 application on my ubuntu server, if I run the rake db:migrate command I getting this error
rake aborted!
ArgumentError: invalid byte sequence in UTF-8
My environment:
Rails 4.1.6
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
here the trace
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/file_list.rb:395:in `glob'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/file_list.rb:395:in `glob'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:258:in `block in have_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:256:in `each'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:256:in `have_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:657:in `find_rakefile_location'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:673:in `raw_load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/root/.rbenv/versions/2.1.2/bin/rake:33:in `<main>'
Any ideas?
On my local machine everything works fine...

What's the data store being used here out of curiosity? Is it possible to just destroy the database and start fresh by chance? If so, you can do that with:
rake db:drop db:create db:migrate

Related

Deploy Rails 2.3.16 application on Heroku, try to migrate database, rake aborted! cannot load such file -- iconv

I am trying to deploy a copy of a Rails 2.3.16 application on Heroku. I pushed the application, and added a PostgreSQL database.
heroku run rake db:migrate
rake aborted!
cannot load such file --iconv
Apparently all new applications will run in ruby 2.0.0, and I have been having a lot of trouble managing versions recently. The old applications run in whatever version they were, which is 1.9.2. Maybe that is related. I looked for a long time, and found things such as:
Ruby 2.0 iconv replacement
in `require': no such file to load -- iconv (LoadError)
I tried gem install iconv
This site doesn't help, or maybe I don't understand what to do:
https://rvm.io/packages/iconv
rvm autolibs rvm_pkg did nothing. rvm autolibs enable didn't help.
This site seemed to say something completely different even though it linked to https://rvm.io/packages/iconv:
http://bullrico.com/2012/09/04/cannot-load-such-file-iconv/
I did:
rvm reinstall 1.9.2-p290 --with-iconv-dir=$rvm_path/usr
At least 2 things failed in that, and iconv issue is not resolved:
Error running 'env GEM_PATH=/Users/RedApple/.rvm/gems/ruby-1.9.2-p290:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290#global:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290:/Users/RedApple/.rvm/gems/ruby-1.9.2-p290#global GEM_HOME=/Users/RedApple/.rvm/gems/ruby-1.9.2-p290 /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -d /Users/RedApple/.rvm/src/rubygems-2.1.4/setup.rb',
please read /Users/RedApple/.rvm/log/1379705294_ruby-1.9.2-p290/rubygems.install.log
Installation of rubygems did not complete successfully.
Error running '__rvm_with ruby-1.9.2-p290 /Users/RedApple/.rvm/scripts/gemsets pristine',
please read /Users/RedApple/.rvm/log/1379705294_ruby-1.9.2-p290/gemset.pristine-ruby-1.9.2-p290.log
heroku run rake db:migrate
rake aborted!
cannot load such file -- iconv
I don't have time to reprogram the 2.3.16 application into 3 or 4 if that is required. I don't even know what iconv is. What is the easiest way to get rid of this error?
Edit:
I put this in the Gemfile and redeployed:
ruby '1.9.2'
I don't know if it is progress, but now a new error:
heroku run rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
bad URI(is not URI?):
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:156:in `split'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:174:in `parse'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/uri/common.rb:628:in `parse'
/app/config/initializers/redis.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:173:in `load'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:173:in `load_with_new_constant_marking'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:622:in `block in load_application_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:621:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:621:in `load_application_initializers'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:176:in `process'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/initializer.rb:113:in `run'
/app/config/environment.rb:11:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `block in require'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:547:in `new_constants_in'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-2.3.16/lib/active_support/dependencies.rb:182:in `require'
/app/vendor/bundle/ruby/1.9.1/gems/rails-2.3.16/lib/tasks/misc.rake:4:in `block in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain'
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Edit:
I didn't read the error message thoroughly, and missed this line:
/app/config/initializers/redis.rb:1:in `<top (required)>'
I commented out these lines, since I don't need Redis yet:
# uri = URI.parse( ENV[ "REDISTOGO_URL" ] )
# REDIS = Redis.new( :host => uri.host, :port => uri.port, :password => uri.password )
heroku run rake db:migrate finally worked.
All of that, and it seems the main problem was solved by adding this line to the Gemfile:
ruby '1.9.2'
Lesson learned: If you have an old application that needs to be redeployed for some other purpose on Heroku, you need to specify the ruby version in the Gemfile.

Problems running rake db:migrate in a Ruby on Rails app

I am trying to run rake db:migrate in my Ruby on Rails application.
However, it is giving me a "uninitialized constant" exception. From Googling this, it looks like the solution is to update the rake version. So I changed my gemfile and ran bundle update.
However, the exception is still happening... I think because I didn't update the right rake library.
How do I fix this? How can I update rake for the other path too, or exclusively run rake through the bundle thing?
My-Comp:my_project username$ bundle show rake
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2
My-Comp:my_project username$ which rake
/usr/bin/rake
My-Comp:my_project username$ rake -V
rake, version 0.8.7
(See - they are not the same!)
My-Comp:my_project username$ rake db:migrate --trace
(in /Users/username/projects/my_project)
rake aborted!
uninitialized constant Rake::DSL
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2503:in `const_missing'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8
/Library/Ruby/Gems/1.8/gems/rdoc-3.12/lib/rdoc/task.rb:37:in `require'
/Library/Ruby/Gems/1.8/gems/rdoc-3.12/lib/rdoc/task.rb:37
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks/documentation.rake:2:in `require'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks/documentation.rake:2
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks.rb:15:in `load'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks.rb:15
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks.rb:6:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/tasks.rb:6
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:289:in `require'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:289:in `initialize_tasks'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie.rb:184:in `instance_exec'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie.rb:184:in `load_tasks'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie.rb:184:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie.rb:184:in `load_tasks'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:424:in `load_tasks'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:145:in `load_tasks'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send'
/Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/username/projects/my_project/Rakefile:7
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2383:in `load'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2383:in `raw_load_rakefile'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2017:in `load_rakefile'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2016:in `load_rakefile'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2000:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:31
Try this command:
bundle exec rake db:migrate
bundle exec executes a command in the context of your gemfile.

Not able to start Rails server

I am working on Ubuntu 10.04 LTS, Lucid Lynx, have installed Ruby on Rails 3 on it. I am not able to start Rails server. I am getting the following error.
mah#mah-laptop:~/Desktop/projects/ver$ rails s
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:29:in `block in <top (required)>': undefined method `root' for nil:NilClass (NoMethodError)
from /home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:27:in `tap'
from /home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I am using Rails 3.0.8 and rake version 0.8.7
I tried bundle exec but got same error.
Thanks for any help in advance
UPDATE
Here is what I get after bundle exec rake db:migrate --trace
mah#mah-laptop:~/Desktop/projects/ver$ bundle exec rake db:migrate --trace
rake aborted!
uninitialized constant Ver
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
/home/mah/Desktop/projects/ver/Rakefile:7:in `<top (required)>'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/home/mah/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load'
/home/mah/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'
This error means that Rails.application isn't initialized. I didn't actually know that, I
cheated.
So that then begs the question: how did you set up this application?
Perhaps this application doesn't contain a config/application.rb file that defines a class that inherits from Rails::Application and therefore is causing this problem. In my application here, I've got this one you could use as an example.

Rake db:migrate issue

When running rake db:create or rake db:migrate locally my app successfully builds the tables as expected. When running on heroku however (eg. heroku rake db:migrate --trace --app ) it is giving me the following error all of a sudden:
C:\>heroku rake db:migrate --trace --app foo rake aborted!
undefined method `task' for #<Foo::Application:0x7f8e77aa1420>
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.4/lib/rails/application.rb:214:in `initialize_tasks'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.4/lib/rails/application.rb:139:in `load_tasks'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.4/lib/rails/application.rb:77:in `send'
/app/.bundle/gems/ruby/1.8/gems/railties-3.0.4/lib/rails/application.rb:77:in `method_missing'
/app/Rakefile:7
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:495:in `raw_load_rakefile'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:78:in `load_rakefile'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:129:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:77:in `load_rakefile'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:61:in `run'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:129:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/lib/rake/application.rb:59:in `run'
/app/.bundle/gems/ruby/1.8/gems/rake-0.9.0/bin/rake:31
/usr/ruby1.8.7/bin/rake:19:in `load'
/usr/ruby1.8.7/bin/rake:19
Looking at the Rakefile this is all that's present:
require File.expand_path('../config/application', __FILE__)
require 'rake'
Foo::Application.load_tasks
The load_tasks line is line 7. I'm really not sure what changed but something sure has. Has anyone had experience with this error?
See that
There's an issue with Rake 0.9.0. Use 0.8.7 in your Gemfile for now.

can't use db:seed in rails

I updated my rails gem to 2.3.5 but I keep getting this error when running db:seed:
$ rake db:seed --trace
(in c:/Documents and Settings/Owner/workspace/thepatstudio)
rake aborted!
Don't know how to build task 'db:seed'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1728:in `[]'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
c:/Ruby/bin/rake:19:in `load'
c:/Ruby/bin/rake:19
~/workspace/thepatstudio (master)
$ rails --version
Rails 2.3.5
My environment.rb has the correct rails version on it and I also ran rake rails:update. What can I do?
Have you launch the rake task to update your environment after update your gem ?
rake rails:update

Resources