I wanna get started with ror but this problem seems unsolvable. I know there are many threads about it this database error but none of the solutions appear to work out. I now searched through the forums all afternoon, with no success.
I basically just perform the first tasks from the textbook, which are as follows:
I create a new RoR project (Windows 10, SQLite3) with
rails new depot
Then I create a scaffold in this project with the following code:
rails generate scaffold Product title:string description:text image_url:string price:decimal
And as i test the application I get the db:migrate error. I tried rake db:migrate, db:rollback, db:drop and then db:create, I checked the migration file for mistakes, but nothing appears to work.
I assume the solution should be quite simple, since the application should be as uncomplex as it gets at this state, but I just cannot get behind the secret it appears.
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:586:in `load_schema_if_pending!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `block in maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:823:in `suppress_messages'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:597:in `method_missing'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_help.rb:15:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Users/Flori/Desktop/bsp/test/test_helper.rb:3:in `<top (required)>'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `require'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:86:in `plugin_rails_init'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:80:in `block in init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:129:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:73:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:62:in `block in autorun'
Switch of your server, then run
rake db:drop db:create db:migrate
This must fix your problem
Related
I'm really new to Ruby and its Rails framework and I was following a tutorial when I ran into some issues using the rails generate command. I tried using rails generate scaffold and rails generate controller but it didn't work. The full trace is this:
/usr/lib/ruby/vendor_ruby/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x000055cdba53c180> (NoMethodError)
from /home/eric/Projects/blog/config/application.rb:12:in `<class:Application>'
from /home/eric/Projects/blog/config/application.rb:10:in `<module:Blog>'
from /home/eric/Projects/blog/config/application.rb:9:in `<top (required)>'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
I think that the main issue is that I'm missing the 'load_defaults' method, but I couldn't find anything on how to resolve the issue. For context, I'm doing this all on a completely new rails project on Ubuntu - the only things I've done so far are rails new and bundle install.
Somewhat curiously, this issue is only popping up on new rails projects that I've created. I tried using rails generate commands on a project I had earlier and it worked. I couldn't figure out what was different between the projects though.
Any suggestions would be greatly appreciated!
I'd like to migrate database to production environment on Heroku.
I typed the following code, however I got error. I have no idea what to do. I'm looking forward to your advice. Thank you for your kindness.
$ heroku run rake db:migrate
Running `rake db:migrate --trace` attached to terminal... up, run.2338
rake aborted!
LoadError: libruby.so.2.2: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg_ext.so
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg.rb:4:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:134:in `require'
/app/config/application.rb:7:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/app/bin/rake:8:in `<main>'
Have you tried running migration directly from the bash inside the heroku server? If not, try the following...
heroku run bash --app your_app_name_goes_here
bundle exec rake db:migrate
First line of code opens the bash command terminal and the second one migrates the db as usual.
This would not be the suggested solution. But, in case you DO NOT care about losing data in the database, you can try and reset the database first and try again. Again, don't do this unless you are willing to lose existing data!
heroku pg:reset DATABASE
heroku run rake db:migrate
However you can perform this via bash as before.
Hope this helps you out.
You can run a dyno in the background using heroku run:detached. Unlike heroku run, these dynos will send their output to your logs instead of your console window. You can use heroku logs to view the output from these commands:$ heroku run:detached rake db:migrate
Running rake db:migrate... up, run.2
Use 'heroku logs -p run.2' to view the log output.
I've never sent this one before. I'm configuring a new server with an existing application. Trying to run a migration and here's the output.
root#beta:/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010# RAILS_ENV=production rake db:migrate --trace
rake aborted!
private method `gsub' called for nil:NilClass
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler/runtime.rb:77:in `require'
org/jruby/RubyArray.java:1614:in `each'
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/config/application.rb:7:in `(root)'
org/jruby/RubyKernel.java:1027:in `require'
/usr/local/rvm/rubies/jruby-1.6.6/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/config/application.rb:4:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/Rakefile:25:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/usr/local/rvm/gems/jruby-1.6.6#foo/bin/rake:19:in `(root)'
Migrations on my local laptop and on an existing server are working fine. config/database.yml looks right. Database is up and running and I can connect to it. What is this?
I also just tested rails console and I'm also not able to get a console. Again a private method gsub called for nil:NilClass. It's somehow related to connecting to the database and I'm not sure how/why.
** UPDATE **
After adding some debug into runtime.rb, this is the exception that's being raised:
#<LoadError: no such file to load -- activerecord-jdbcmysql-adapter>
The messed up part is, it is installed:
# gem list |grep -i activerecord-jdbcmysql-adapter
activerecord-jdbcmysql-adapter (1.2.2)
Is this some kind of RVM or bundler bug?
** LAST UPDATE **
I installed Amazon Linux AMI (The other is running an Ubuntu) and cannot replicate this issue there.
This is a bug in bundler, it was reported for rvm-capistrano, please check your Gemfile and try removing / commenting some gems.
https://github.com/carlhuda/bundler/issues/1801
Ok so I am a ruby on rails developer and I am about to start trying to use the TDD (test driven development) approach and I am not sure what I am doing wrong. I have an existing app that has some rpec tests already and I am trying to figure how to run them but when i do
rake spec
(in /Users/tamer/Sites/preview)
/Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant PreviewsController (NameError)
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/tamer/Sites/preview/spec/controllers/previews_controller_spec.rb:3:in `<top (required)>'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
(See full trace by running task with --trace)
Is there something that i am missing and what I need to do to get the previous tests to run
The error is pretty self-explanatory.
uninitialized constant PreviewsController (NameError)
Chances are the PreviewsController class referenced by ./spec/controllers/previews_controller_spec.rb no longer exists in /app/controllers.
Either update the spec or remove it if the corresponding controller has been removed.
I am following the rails tutorial at railstutorial.org
I'm in chapter 2 and tried to migrate the database using rake as per the instructions: "To proceed with the demo application, we first need to migrate the database using Rake (Box 2.1)":
$ rake db:migrate
This did not work and I received the following error:
C:\Users\USER1\rails_project\demo_app>rake db:migrate
(in C:/Users/USER1/rails_project/demo_app)
rake aborted!
uninitialized constant Rake::DSL
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
C:/Users/USER1/rails_project/demo_app/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
C:/Ruby192/bin/rake:31:in `<main>'
How can I resolve this?
This is a problem with the new (just released) version of rake. You can solve it by downgrading rake to 0.8.7. It's the simpler solution for a tutorial. See Rake 0.9.0 'undefined method 'task' ' and answers to that question.
You might add rake 0.8.7 to your Gemfile, like:
gem 'rake', '0.8.7'
And in the terminal you should run with
bundle exec rake db:migrate
And you are ready to follow, i hope this will help you.
I know you would have solved this issue long back but just in case anyone needs to know Rake .9.0 breaks Rails and several other things, you need to either go back to previous version or update the latest one (11.1.2):
gem "rake", "11.1.2"
in your Gemfile.
And then just follow these commands:
$ bundle update rake
Then check the rake with:
$ bundle show rake
And it should show rake 11.1.2.
After this you can successfully run
$ bundle exec rake db:migrate
(PS: hope this helps someone :) )