更新:Sqlite3 gem rails无法在heroku和本地env

时间:2016-06-06 09:26:42

标签: ruby-on-rails ruby git heroku sqlite

我在rails博客中使用heroku。能够在此处修复gem文件之后的许多相关答案,并能够将我的博客推送到heroku,该应用程序无法在本地工作。

我已经改变了#sqlite3'为了''在我的制作环境中添加' sqilte3'仅在开发测试中,将我的更改推送到git,然后推送到heroku。到目前为止它工作正常,但是当我尝试运行rails服务器时,是要求我提供' sqlite3'试。

错误:

  

rb:177:在rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem' sqlite3'`到您的Gemfile(并确保其版本达到ActiveRecord所需的最低要求)。 (GEM :: LoadError)

GEMFILE 



source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'devise'

gem 'will_paginate', '~> 3.0.5'

gem 'cancancan'

gem "paperclip", "~> 5.0.0.beta1"

gem 'ratyrate'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  gem "sqlite3"

  gem 'rspec-rails', '~> 3.0'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :production do
  gem 'rails_12factor'
  gem 'pg'
end
&#13;
&#13;
&#13;

DATABASE.YML

&#13;
&#13;
# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# 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:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3
&#13;
&#13;
&#13; 我按照这里的步骤&gt;&gt; http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast&gt;&gt;现在正在工作。注意初学者,如果你打算使用rails而heroku用pg启动你的应用程序来节省调试时间。

3 个答案:

答案 0 :(得分:1)

我知道这是一个非常老的问题,但昨天我也遇到了同样的问题,正在使用Ubuntu 16.04 Rails 5.1.6

我尝试了所有在网络上找到的解决方案,但对我没有任何帮助,所以我正在为我编写解决该问题的方法,以便它可以帮助解决此问题的人。

只需检查您使用的Sqlite3 gem的版本:

bundle show sqlite3

对我来说是sqlite3-1.4.0

现在只需降级到sqlite3 gem的旧版本  只需在您的gemfile中添加gem 'sqlite3', '~> OLDER VERSION'即可替换您当前版本的sqlite3

bundle install

就是这样,它应该可以工作。

答案 1 :(得分:0)

如果你在生产中使用pg而不是......为什么在这里使用sqlite3

production:
  <<: *default
  database: db/production.sqlite3

从pg配置更新。

Heroku与sqlite3不兼容,你应该使用pg

Pg config。

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password:

答案 2 :(得分:0)

我建议删除database.yml的整个默认部分,然后为其余部分设置所有内容:

development:
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: db/development.sqlite3

test:
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  database: <project name>
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>