heroku Sinatra加载错误:加载“sqlite3”活动记录适配器时出错

wnavrhmk  于 2022-11-13  发布在  SQLite
关注(0)|答案(1)|浏览(142)

你好,我正试图推动sinatra回购dokku,但每次出来这个错误
rake中止!LoadError:加载“sqlite3”活动记录适配器时出错。缺少它所依赖的gem?sqlite3不是捆绑包的一部分。请将它添加到gem文件中。
似乎是环境文件上的此配置导致了此问题

ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)

这是文件

ENV["SINATRA_ENV"] ||= "development"
require "bundler/setup"
Bundler.require(:default, ENV["SINATRA_ENV"])



require "rack-flash"
require "sinatra/json"
require "sprockets"
require "friendly_id"



ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)


  
# Load initializers
Dir["./config/initializers/**/*.rb"].each { |file| require file }

require_all "app"

我将sqlite gem放入开发组

group :development do
  gem "letter_opener"
  gem "sqlite3"
 
end

我已经试过rails_12factor和ubyracer了,但是问题还是这样,有人知道为什么吗?
放入gem文件

gem 'rails_12factor'
gem 'therubyracer'

database.yml

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  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
  adapter: postgresql
  encoding: unicode
  port: 5432
  database: postgres://postgres:xxxxxxxxxxx@dokku-postgres-yyyyyy-db:5432/yyyyy_db

日志

Caused by:
       Gem::LoadError: sqlite3 is not part of the bundle. Add it to your Gemfile.
       /tmp/build/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.10/lib/bundler/rubygems_integration.rb:291:in `block (2 levels) in replace_gem'
       /tmp/build/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>'
r1wp621o

r1wp621o1#

只需在environment.rb上设置环境数据库

configure :development do
ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)
end

相关问题