2010-10-09 84 views
37

我試圖將我的第一個應用程序部署到Heroku。我使用Sqlite作爲數據庫。據我所知Heroku不使用Sqlite - 它在後臺切換到Postgres。使用Sqlite3將RoR應用程序部署到Heroku

當我部署我得到以下錯誤:

/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in `require': no such file to load -- sqlite3 (LoadError)

我的Gemfile(這是我認爲是造成這個問題),如下所示:

source 'http://rubygems.org' 

gem 'rails', '3.0.0'   
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3' 

我在做什麼錯誤?

+0

如何在本地運行它?我在我的所有寶石文件中都有sqlite,並且與heroku沒有任何問題。你捆綁了嗎? – 2010-10-09 19:59:26

+0

我不認爲我很理解捆綁的概念。捆綁包是做什麼的? (鏈接將會這樣做) – 2010-10-10 11:39:27

+0

[將SQLite3推到Heroku失敗]重複(http:// stackoverflow。com/questions/3747002 /推動rails-with-sqlite3-to-heroku-失敗) – 2014-05-25 20:51:16

回答

53

Heroku不支持SQLite數據庫。您需要在生產中使用PostgreSQL,如I also explained in this post

group :production do 
    gem "pg" 
end 

group :development, :test do 
    gem "sqlite3", "~> 1.3.0" 
end 

實際上,它被推薦用於開發/測試環境儘可能接近生產。因此,我建議您將所有環境切換到PostgreSQL。

# replace gem "sqlite3" with 
gem "pg" 
+0

你確定嗎?我一直在RailsTutorial.org - 作者部署到Heroku而不會改變任何東西 – 2010-10-10 11:43:09

+0

在這裏閱讀http://docs.heroku.com/database – 2010-10-10 16:32:03

+4

謝謝,我不知道爲什麼愚蠢的教程不提到那個 – 2010-10-10 18:28:38

-4

我正在使用sqlite3並部署到Heroku沒有問題。這裏是我的database.yml

# SQLite version 3.x 
# gem install sqlite3-ruby (not necessary on OS X Leopard) 
development: 
    adapter: sqlite3 
    database: db/development.sqlite3 
    pool: 5 
    timeout: 5000 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    adapter: sqlite3 
    database: db/test.sqlite3 
    pool: 5 
    timeout: 5000 

production: 
    adapter: sqlite3 
    database: db/production.sqlite3 
    pool: 5 
    timeout: 5000 
+7

database.yml文件並不重要 - 「爲了簡化典型Rails應用程序的部署,Heroku在部署時自動生成一個新的database.yml文件」 – 2010-10-10 18:37:19

3

西蒙娜卡萊蒂是正確的,所以是Joost。您只需將sqlite3 gem分組或將其從Gemfile中完全刪除即可。 Heroku的只需要知道你不想使用sqlite3的生產

所以這個:

... 
group :development, :test do 
    gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3" 
end 
... 

或者這樣:

... 
#No reference to sqlite3-ruby 
... 

如果刪除完全引用你大概會亂你的本地數據庫雖然

0

敲我的頭靠在這個問題後,我意識到,我推着我的回購協議的Heroku的分支,而我是讓所有我的postgres更改了我的deploy-postgres我的回購分支!

我合併我部署,Postgres的分支與本地主[git checkout master; git merge deploy-postgres],然後可以運行git push heroku master按照Heroku的文檔。