原来是 rails4.1,ruby2.2,现在进行了升级,使用了 rails 7.0.4 ruby 3.2。 启动后,为什么会这样:
/home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.5/lib/active_record/database_configurations.rb:217:in `build_db_config_from_string': '{ production => production_sec }' is not a valid configuration. Expected 'production_sec' to be a URL string or a Hash. (ActiveRecord::DatabaseConfigurations::InvalidConfigurationError)
from /home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.5/lib/active_record/database_configurations.rb:203:in `build_db_config_from_raw_config'
from /home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.5/lib/active_record/database_configurations.rb:129:in `resolve'
from /home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.5/lib/active_record/connection_handling.rb:353:in `resolve_config_for_connection'
from /home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.5/lib/active_record/connection_handling.rb:51:in `establish_connection'
from /opt/app/art/current/app/models/artwork.rb:2:in `<class:Artwork>'
from /opt/app/art/current/app/models/artwork.rb:1:in `<top (required)>'
from <internal:/home/ubuntu/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
config/database.yml是这样的:
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: xx
host: 172.17.0.1#(使用了docker mysql 5.7)
port: 3306
development: &development
<<: *default
database: web
test: &test
<<: *default
database: web_test
production: &production
<<: *default
database: web
development_sec: &development
<<: *default
database: art
test_sec: &test
<<: *default
database: art_test
production_sec: &production
<<: *default
database: art
在 model 进行了数据库的选择
class Artwork < ActiveRecord::Base
ActiveRecord::Base.establish_connection("#{Rails.env}_sec")
#establish_connection :test_sec
#ActiveRecord::Base.establish_connection(
# "mysql2://root:[email protected]/art_test"
#)
#self.table_name = "artworks"
我尝试修改了连接数据库 的方式,但是无法连接,应该怎么解决?