簡體   English   中英

bundle exec rake assets:precompile - 數據庫配置沒有指定適配器

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

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

簡單的解決方案是在我的application.rb中添加一個簡單的行

config.assets.initialize_on_precompile = false

一切正常。

這應該工作:rake資產:預編譯RAILS_ENV =開發

當您的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

# 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”。

對我有用的是:

rake assets:precompile RAILS_ENV=production

通過ssh訪問您的服務器並輸入該命令,它應該可以解決問題。

這個解決方案停止了使用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

確保在本地config/database.yml文件中有一些虛擬 production條目

production:
  <<: *default
  database: your_local_database_name

我在2016年遇到了與Rails 4.2.6和Capistrano 3.4相同的錯誤。 我們在部署腳本期間預先編譯資產,然后將它們與代碼一起上傳,但是rake資產:預編譯需要一些生產條目,即使它只是一個虛擬條目。 資料來源: https//github.com/TalkingQuickly/capistrano-3-rails-template/issues/12

調用rake assets:precompile:all

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM