如何设置应用程序在heroku上运行?正在获取sqlite3错误



我正在尝试将我的应用程序推送到heroku。我在终端中收到错误消息:安装sqlite3(1.3.11)时出错,Bundler无法继续。此外,在绑定之前,请确保gem install sqlite3 -v '1.3.11'成功。我读了很多关于sqlite2和pg的文章,但似乎不知道如何将其集成到我的gemfile中。非常感谢。

这是我的gemfile:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# 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
# 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'
  # 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'

结束

感谢

SQLite是启动项目的好方法,在本地机器上处理小数据集时效果良好。另一方面,Heroku需要比SQLite提供的多一点。当使用Heroku和Rails时,他们更喜欢你使用PostgreSQL。查看他们在SQLite和PostgreSQL 上的文档

https://devcenter.heroku.com/articles/sqlite3

与最初使用PG数据库制作应用程序相比,切换到PG数据库需要更多的工作,但这并非不可能。上面的链接有一些步骤可以帮助您将SQLite转换为PostgreSQL。

Heroku有很棒的Rails集成文档。如果你需要更多信息,请查看https://devcenter.heroku.com/categories/ruby

要在您的项目中使用sqlite3,请在您的gemfile上单击以下行:

gem 'sqlite3'

要使用postgres作为数据库,请添加:

gem 'pg'

记住在你的系统上安装postgres包,如果你使用的是ubuntu,它应该是:

sudo apt-get install postgres libpq-dev

Tim是对的,Heroku不支持SQLite,更喜欢使用PostgreSQL。然而,如果您已经启动了rails应用程序并准备推送到heroku,那么毫无疑问,您已经开始使用SQLite,因此在尝试推送时会出现错误。目前,您的Gemfile中既没有PostgreSQL(pg)也没有SQLite(sqlite3),这可能会导致它自己的一系列问题。

为了解决这个问题,您可以在Gemfile 中使用生产和测试分组

group :production do
  gem 'pg'
end
group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
  gem 'other-gems'
end

如果您没有使用Heroku设置临时环境,那么在部署时,PostgreSQL(pg)将成为默认的数据库设置。允许您继续在本地使用您已经做过的任何事情以及生产中的PostgreSQL。

最新更新