【问题标题】:bundle exec rake assets:precompile - database configuration does not specify adapterbundle exec rake assets:precompile - 数据库配置未指定适配器
【发布时间】:2012-06-04 10:07:52
【问题描述】:

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

我跑了

rake assets:precompile RAILS_ENV=production

我不断收到此错误。

/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...]

我的 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

【问题讨论】:

  • m8 你的生产数据库配置在哪里?))
  • Heroku 上不需要它。 Heroku 为您处理。抱歉,我忘了提到我使用的是 heroku。

标签: ruby-on-rails postgresql


【解决方案1】:

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

config.assets.initialize_on_precompile = false

一切正常。

【讨论】:

  • 请注意:确保将上述行添加到您的 config/application.rb 中。我错误地将它添加到 config/environments/production.rb 中,这将不起作用
  • Rails 4.x 中的 PSA 此选项已被删除
【解决方案2】:

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

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

【讨论】:

  • 给使用 Asset Sync 的任何人的说明。将 RAILS_ENV 设置为 development 将阻止 Asset Sync 在编译后同步。
【解决方案3】:

这样做:

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 会用它自己的版本覆盖你的 database.yml,不管你在里面放了什么。 但是,您在生产环境中运行的 rake 任务需要一个变量,所以给它一个虚拟变量。

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

【讨论】:

  • 值得注意的是,从 Rails 4 Heroku 开始现在不再覆盖你的 database.yml
【解决方案4】:

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

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

命令是: bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname assets:precompile

【讨论】:

    【解决方案5】:

    对我有用的是:

    rake assets:precompile RAILS_ENV=production

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

    【讨论】:

      【解决方案6】:

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

      production:
        <<: *default
        database: your_local_database_name
      

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

      【讨论】:

        【解决方案7】:

        致电rake assets:precompile:all

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-13
          • 1970-01-01
          • 2015-11-26
          相关资源
          最近更新 更多