微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails 6 无法加载数据库 config.yml

如何解决Rails 6 无法加载数据库 config.yml

当应用程序移入云时,它显示以下错误。从研究中我发现这是 yml 文件中的制表符问题,因此我将其更改为空格但仍然出现相同的错误

rails c
das@ubuntu-s-1vcpu-1gb-blr1-01:~/lpm-rails$ /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/configuration_file.rb:24:in `rescue in parse': Cannot load database configuration:
YAML Syntax error occurred while parsing /home/das/lpm-rails/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unkNown>): found character that cannot start any token while scanning for the next token at line 17 column 13 (RuntimeError)
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/configuration_file.rb:21:in `parse'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/configuration_file.rb:18:in `parse'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/railties-6.1.1/lib/rails/application/configuration.rb:275:in `database_configuration'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activerecord-6.1.1/lib/active_record/railtie.rb:221:in `block (2 levels) in <class:Railtie>'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activerecord-6.1.1/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/activerecord-6.1.1/lib/active_record/base.rb:15:in `<main>'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:376:in `active_record_configured?'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:293:in `disconnect_database'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:111:in `preload'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
        from /usr/share/rvm/gems/ruby-3.0.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
        from <internal:/usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

这是在在线 yml 验证器中验证的 db 文件,它似乎是正确的

# MysqL. Versions 5.5.8 and up are supported.
#
# Install the MysqL driver
#   gem install MysqL2
#
# Ensure the MysqL gem is defined in your Gemfile
#   gem 'MysqL2'
#
# And be sure to use new-style password hashing:
#   https://dev.MysqL.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
  adapter: MysqL2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV['DB_USER'] %>
  password: <%= ENV['DB_PASSWORD'] %>
  socket: /tmp/MysqL.sock

development:
  <<: *default
  database: <%= ENV['DB'] %>

# 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: backend_lpm_test

# As with config/credentials.yml,you never want to store sensitive information,# like your database password,in your source code. If your source code is
# ever seen by anyone,they Now have access to your database.
#
# Instead,provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
#   DATABASE_URL="MysqL2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable,Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively,you can specify a connection
# URL environment variable explicitly:
#
#   production:
#     url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
  <<: *default
  database: <%= ENV['DB'] %>
  username: <%= ENV['DB_USER'] %>
  password: <%= ENV['BACKEND_LPM_DATABASE_PASSWORD'] %>

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。