美文网首页
Rails 无法生成页面,没有"config/database.

Rails 无法生成页面,没有"config/database.

作者: 大猫城堡 | 来源:发表于2017-06-25 10:18 被阅读0次

    终端报错

    $rails g controller welcome
    
    /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/application/configuration.rb:143:in `database_configuration': Cannot load `Rails.application.database_configuration`:
    
    Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/railtie.rb:122:in `block (2 levels) in '
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `each'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/base.rb:324:in `'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/base.rb:24:in `'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:338:in `active_record_configured?'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:259:in `disconnect_database'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:97:in `preload'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:143:in `serve'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    
    from /Users/lvchengbo/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `'
    
    from /Users/lvchengbo/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    
    from /Users/lvchengbo/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    
    from -e:1:in `<main>`
    

    解决办法

    运行命令,生成文件 config/database.yml

    touch config/database.yml
    

    贴进去

    # SQLite version 3.x
    #   gem install sqlite3
    #
    #   Ensure the SQLite 3 gem is defined in your Gemfile
    #   gem 'sqlite3'
    #
    default: &default
      adapter: sqlite3
      pool: 5
      timeout: 5000
    
    development:
      <<: *default
      database: db/development.sqlite3
    
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      <<: *default
      database: db/test.sqlite3
    
    production:
      <<: *default
      database: db/production.sqlite3
    

    相关文章

      网友评论

          本文标题:Rails 无法生成页面,没有"config/database.

          本文链接:https://www.haomeiwen.com/subject/quilcxtx.html