【发布时间】:2020-10-23 11:44:42
【问题描述】:
免责声明:我知道有几个关于这个问题的问题,但我遵循了所有的答案。发布在这些问题中,我仍然收到错误。
我有一个使用 Postgres 设置的 Rails 应用程序,并正在尝试切换到 mongoid。以下是我采取的步骤:
- 删除数据库
- 添加
'mongoid', '~> 7.0.5'并删除'pg'gem - 删除所有对
active_record和active_storage的引用 - 移除弹簧宝石(已知会导致问题)
- 更新所有型号以兼容
mongodb - 删除
config/database.yml和/db目录 - 切换
devise和database-cleaner以使用mongoid
按照上述所有步骤操作后,我在启动服务器时仍然收到错误:
Could not load database configuration - No such file - [config/database.yml]
这没有任何意义,因为 rails 根本不应该加载活动记录,因此不应该加载数据库配置文件。
如果有人可以调试此问题,我将不胜感激。
您可以查看source code of my app under the branch mongodb
编辑:我禁用了bootsnap 和devise 并将堆栈跟踪归结为:(看起来像active_record is still being loaded)
Puma caught this error: Cannot load database configuration:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/railties-6.0.3.2/lib/rails/application/configuration.rb:241:in `database_configuration'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/railtie.rb:200:in `block (2 levels) in <class:Railtie>'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/base.rb:327:in `<module:ActiveRecord>'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/base.rb:27:in `<top (required)>'
/Users/afamily/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
/Users/afamily/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/query_cache.rb:31:in `run'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:28:in `before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:428:in `block in make_lambda'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:200:in `block (2 levels) in halting'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:605:in `block (2 levels) in default_terminator'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:604:in `catch'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:604:in `block in default_terminator'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:201:in `block in halting'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `each'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `invoke_before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:134:in `run_callbacks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:111:in `run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:73:in `block in run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:70:in `tap'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:70:in `run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/static.rb:126:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/webpacker-4.2.2/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/railties-6.0.3.2/lib/rails/engine.rb:527:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/configuration.rb:228:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:713:in `handle_request'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:472:in `process_client'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:328:in `block in run'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
【问题讨论】:
-
哪个分支是无设计的?
-
@D.SM 我没有提交无设计版本,因为它不成功。但是,我创建了一个新的 rails 应用程序跳过了活动记录,并添加了设计,它很好,所以我不知道这是否是问题
-
@D.SM 我通过将所有代码复制粘贴到配置了 mongoid 的新 Rails 应用程序中来解决了这个问题。不知道它是如何工作的,git 说它所做的只是删除了一堆 cmets ¯_(ツ)_/¯。不过感谢您的帮助
标签: ruby-on-rails database mongodb postgresql mongoid