首页 文章

使用SQLite 3将RoR应用程序部署到Heroku失败

提问于
浏览
37

我正在尝试将我的第一个应用程序部署到Heroku . 我正在使用SQLite作为数据库 . 据我所知,Heroku不使用SQLite - 它在后端切换到Postgres .

当我正在部署时,我收到以下错误:

/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in`requirement':没有要加载的文件--sqlite3(LoadError)

我的 Gemfile (这是我假设导致此问题)如下所示:

source 'http://rubygems.org'

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

我究竟做错了什么?

6 回答

  • -4

    你可以用clearDB addon

    gem 'mysql2' 而不是 gem 'sqlite3'

  • 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

    Simone Carletti是正确的,Joost也是如此 . 您只需要对sqlite3 gem进行分组或将其从Gemfile中完全删除 . Heroku只需要知道你不想使用sqlite3进行 生产环境

    所以这:

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

    或这个:

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

    如果你完全删除引用,你可能会搞乱你的本地数据库

  • 3

    我在这里看了几个小时都被困在这里,但是我无法得到足够的细节来让它融合在一起 . 这个分页让我了解了一切 . http://railsapps.github.io/rails-heroku-tutorial.html

    祝好运 .

  • 0

    在我的头撞到这个问题之后,我意识到我正在把我的仓库的主分支推到heroku,而我在我的repo的deploy-postgres分支中进行了所有postgres更改!

    我将deploy-postgres分支与我的本地主[ git checkout master; git merge deploy-postgres ]合并,然后根据heroku文档运行 git push heroku master .

  • -2

    我正在使用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
    

相关问题