konchanxxx / menta

MENTAのタスク管理用リポジトリ
0 stars 0 forks source link

Railsでmodel作成の際に、エラーが出る #37

Closed konoken closed 5 years ago

konoken commented 5 years ago

概要

rails g model Pin title:string description:textを実行した際に、sqlite3に関するエラーが発生

実現したいこと

modelを作成したい

困っていること

エラーがでて、先に進めない。

困っていることがバグの場合は事象やログ、エラーメッセージをできるだけそのまま(抜粋などしない)下記に記載してください。

mbp:pin_board mac$ rails g model Pin title:string description:text 
[Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
/Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/connection_specification.rb:185:in `spec'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/connection_handling.rb:58:in `establish_connection'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:49:in `each'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.1.6.1/lib/active_record/base.rb:25:in `<top (required)>'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `require'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `block in require'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:258:in `load_dependency'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `require'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:356:in `active_record_configured?'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:273:in `disconnect_database'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:107:in `preload'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/kenkono/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

解決するために行ったこと

gemにsqlite3がインストールされているかgem listで確認をした(下記)

mbp:pin_board mac$ gem list sqlite3

*** LOCAL GEMS ***

sqlite3 (1.4.0)

また、エラーメッセージに書かれているGemfile内にgem 'sqlite3'が書かれていることを確認した。

問題となっている箇所の予想

Gemfileの記述。 しかし、ファイルにはgem 'sqlite3'はすでに書かれており、かつbundle installも実施済み。 エラーの原因がわからない。

問題となっているアプリケーションのGitHub URL

https://github.com/kenkono/pin_picture

konchanxxx commented 5 years ago

確認しますmm

konchanxxx commented 5 years ago

sqliteのバージョンでエラーになるみたいですね こちらの対応で解決できそうでした:bow:

gem 'sqlite3', '~> 1.3.13'

にしてbundle installし直したところ動作しました:bow:

https://qiita.com/katsuyan/items/dd812e2e8fc89d954197

kenkono commented 5 years ago

確認したところ、正常に動作しました! ただ、参照元の記事から、なぜこのようなエラーが起きたのかがいまいちわからず、、、 sqliteのバージョンを1.3.13以上1.4未満に指定していることは~>1.3.13から、わかりますが、最新版(1.4)はバグが報告されているということなのでしょうか?

konchanxxx commented 5 years ago

railsのバグとしてissueがあがっているみたいですね https://github.com/sparklemotion/sqlite3-ruby/issues/249 rails5.2系だと直ってるみたいです:bow: バグの詳細まではみれておりません...orz

konoken commented 5 years ago

確かに、記事書かれている通りのことでした。 ご確認、ありがとうございます!