postgresql bundle exec rake assets:precompile - 数据库配置没有指定适配器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10879587/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:58:34  来源:igfitidea点击:

bundle exec rake assets:precompile - database configuration does not specify adapter

ruby-on-railspostgresql

提问by Benjamin

After 24 hours of trying to find the problem with my app. I finally found the problem.

经过 24 小时试图找到我的应用程序的问题。我终于找到了问题所在。

I ran

我跑了

rake assets:precompile RAILS_ENV=production

and i kept on getting this error.

我一直收到这个错误。

/Users/vezu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /Users/vezu/.rvm/gems/ruby-1.9.3-p194@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
database configuration does not specify adapter

Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/vezu/.rvm/rubies/ruby-1.9.3-p194/bi...]

My database.yml file looks like this

我的 database.yml 文件看起来像这样

development:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: ndoda_test
  pool: 5

回答by Benjamin

The simple solution was to add one simple line to my application.rb

简单的解决方案是在我的 application.rb 中添加一个简单的行

config.assets.initialize_on_precompile = false

And everything works.

一切正常。

回答by Duke

This should work: rake assets:precompile RAILS_ENV=development

这应该有效:rake assets:precompile RAILS_ENV=development

It tries to load up your production environment, when your database.yml doesn't include it.

当您的 database.yml 不包含它时,它会尝试加载您的生产环境。

回答by Leo Ajc

Do this:

做这个:

development:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: ndoda_test
  pool: 5

# Add the below...

production:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: ndoda_production
  pool: 5
  username:
  password:

Heroku will overwrite your database.yml with its own version, regardless of what you put in there. However, your rake task running in the Production environment requires a variable, so give it a dummy one.

Heroku 会用它自己的版本覆盖你的 database.yml,不管你在那里放了什么。但是,在生产环境中运行的 rake 任务需要一个变量,所以给它一个虚拟变量。

As noted above, you can also add 'config.assets.initialize_on_precompile = false' to your production.rb. If set, Heroku requires it be set to 'false'.

如上所述,您还可以将“config.assets.initialize_on_precompile = false”添加到您的 production.rb。如果设置,Heroku 要求将其设置为“false”。

回答by Yazan Khalaileh

This solution stopped working with rails 4, here is the updated one: just pass a dummy database as mentioned in this article:

此解决方案停止使用 rails 4,这是更新的解决方案:只需传递本文中提到的虚拟数据库:

https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0

https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0

The command is: bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname assets:precompile

命令为:bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname assets:precompile

回答by Hugo Sequeira

Make sure you have some dummyproductionentry in your local config/database.ymlfile

确保您的本地文件中有一些虚拟production条目config/database.yml

production:
  <<: *default
  database: your_local_database_name

I've come across the same error in 2016 with Rails 4.2.6 and Capistrano 3.4. We were precompiling the assets during the deploy script just before uploading them together with the code, but rake assets:precompile needs some production entry, even if it's just a dummy one. Source: https://github.com/TalkingQuickly/capistrano-3-rails-template/issues/12

我在 2016 年使用 Rails 4.2.6 和 Capistrano 3.4 遇到了同样的错误。在将资产与代码一起上传之前,我们在部署脚本期间对资产进行了预编译,但是 rake assets:precompile 需要一些生产条目,即使它只是一个虚拟条目。来源:https: //github.com/TalkingQuickly/capistrano-3-rails-template/issues/12

回答by Breno

What worked for me was this:

对我有用的是:

rake assets:precompile RAILS_ENV=production

rake assets:precompile RAILS_ENV=production

Access your server via ssh and type that command in, it should do the trick.

通过 ssh 访问您的服务器并输入该命令,它应该可以解决问题。

回答by grosser

call rake assets:precompile:all

称呼 rake assets:precompile:all