Ruby-on-rails rails:无法加载数据库配置。没有这样的文件 -
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32539062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rails : Could not load database configuration. No such file -
提问by Arun Anand
I cloned an app folder from a GitHub repository, and after bundle install the gems, I tried to use the rake db:setup and rake db:migrate commands, neither worked, and here is my error message:
我从 GitHub 存储库克隆了一个应用程序文件夹,在捆绑安装 gems 后,我尝试使用 rake db:setup 和 rake db:migrate 命令,但都没有奏效,这是我的错误消息:
**arun997@promanager:~/workspace (master) $ rake db:setup
require 'rails/all'... 2.470s
Bundler.require... 7.590s
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file -
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.1.13/lib/rails/application/configuration.rb:105:in `database_configuration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.13/lib/active_record/railtie.rb:41:in `block (3 levels) in <class:Railtie>'
Could not load database configuration. No such file -
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.1.13/lib/rails/application/configuration.rb:105:in `database_configuration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.13/lib/active_record/railtie.rb:41:in `block (3 levels) in <class:Railtie>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create => db:load_config
(See full trace by running task with --trace)**
If anyone can help with i would be eternally grateful.
如果有人可以帮助我,我将永远感激不尽。
回答by The Fabio
Would your rails app be missing the file:
您的 rails 应用程序是否会丢失该文件:
/your-app-path/config/database.yml
if so you can create a fresh one with these examples
如果是这样,您可以使用这些示例创建一个新的
回答by panwar001
Remove .example extension from .yml files
从 .yml 文件中删除 .example 扩展名
database.yml.example -> database.yml
回答by BnakJM
step: cp config/database.yml.example config/database.yml bundle check bundle install rails s again
步骤:cp config/database.yml.example config/database.yml bundle check bundle install rails s
回答by hofffman
I meet this problem, too. Opened my file: config, found in the file, have a file named "database.yml.example", but haven't file "database.yml". So I copy this file from the other project, and this problem solved.
我也遇到这个问题。打开我的文件:config,在文件中找到了一个名为“database.yml.example”的文件,但没有文件“database.yml”。所以我从另一个项目复制了这个文件,这个问题就解决了。
回答by fuzzygroup
Restart spring:
重启弹簧:
bin/spring stop
垃圾箱/弹簧挡块
bin/spring start
垃圾箱/弹簧启动
Spring is an in memory pre-loader for before performance. If you do something crazy like change your Rails application directory and then re git clone, the underlying directory that Spring owns will be internally different and that will cause this to fail. And you will think that you are going insane; you're not -- Spring can be a mild pissant at times.
Spring 是一个用于性能之前的内存预加载器。如果你做了一些疯狂的事情,比如改变你的 Rails 应用程序目录,然后重新 git clone,Spring 拥有的底层目录将在内部不同,这将导致失败。你会认为你快疯了;你不是——春天有时会很温和。
回答by rjmAmaro
For the ones that came here, right after cloning a Rails 5.2 (or newer)project, you might be missing the master.keyfile. Ask the project owner for the file.
对于那些来到这里的人,在克隆Rails 5.2(或更新的)项目之后,您可能会丢失该master.key文件。向项目所有者索要文件。
At the folder your-rails-project/config/you will have a credentials.yml.encfile. It is an encrypted file with the credentials of the project, which is decrypted with the key in the master.keyfile.
在文件夹中,your-rails-project/config/您将有一个credentials.yml.enc文件。它是一个带有项目凭据的加密文件,用文件中的密钥解密master.key。
Rails needs to access the credentials file to be able to execute, even when only preparing the database (rails db:prepare, as in the bin/setupfile).
Rails 需要访问凭据文件才能执行,即使只准备数据库(rails db:prepare,如bin/setup文件中所示)。
For more info: https://guides.rubyonrails.org/security.html#custom-credentials.
更多信息:https: //guides.rubyonrails.org/security.html#custom-credentials。

