Error loading the 'sqlite3' Active Record adapter. when I deploy in Heroku

后端 未结 5 1095
小鲜肉
小鲜肉 2021-01-26 03:55

I have a problem when I am deploying in Heroku:

/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in         


        
相关标签:
5条回答
  • 2021-01-26 04:31

    I had a similar problem and changing the adapter only in production worked for me, so database.yml is like:

    default: &default
      adapter: sqlite3
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      timeout: 5000
    
    development:
      <<: *default
      database: db/development.sqlite3
    
    test:
      <<: *default
      database: db/test.sqlite3
    
    production:
      <<: *default
      adapter: postgresql
      database: db/production.sqlite3
    

    Hope it works for somebody else.

    0 讨论(0)
  • 2021-01-26 04:35

    Heroku doesn't natively support SQLite3, and although I see you added the pg gem in production, you'll also need to configure your Rails application to load its database from PostgreSQL by editing config/database.yml to connect to PostgreSQL.

    0 讨论(0)
  • 2021-01-26 04:49

    You specify sqlite3 as the default adapter under the default: section of your database.yml:

    default: &default
      adapter: sqlite3
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      timeout: 5000
    

    which is causing your error since sqlite3 isn't installed in production.

    You should follow the link that Sebastian Palma provides in the comments. There, you will find a discussion of how to configure your app to use PostgreSQL on Heroku.

    0 讨论(0)
  • 2021-01-26 04:53

    Heroku doesn't natively support SQLite3.

    First open your Gemfile and remove this line:

    gem 'sqlite3'
    

    Replace with this line:

    gem 'pg'
    

    Then run bundle install.

    Next you will need to convert your config/database.yml. Open the existing file, which might look something like this:

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

    You will need to change the adapter from

    adapter: sqlite3
    

    to this:

    adapter: postgresql
    

    Note the adapter name is postgresql not postgres or pg. You will also need to change the database: to a custom name. A final version might look something like this:

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      timeout: 5000
    
    development:
      <<: *default
      database: my_database_development
    
    test:
      <<: *default
      database: my_database_test
    
    production:
      <<: *default
      database: my_database_production
    

    Once you’ve installed the pg gem and migrated your config/database.yml file you will need to create your database and run any pre-existing migrations.

    Now when you push to Heroku using Rails, a development grade PostgreSQL instance will be provisioned and connected to your application automatically. If you’re not using Rails, you may need to manually add the PostgreSQL addon by running

    heroku addons:create heroku-postgresql
    
    0 讨论(0)
  • 2021-01-26 04:54

    You should remove SQLite from your application and use Postgres in development, testing and production. There are many small incompatibilities between RDBMS's and you don't want to discover them when you push your app to production.

    1. Install Postgres on the local system.

    How to do this depends on your system. OS-X and Windows have simple installers. On Linux you would install it through your package manager.

    2. Remove the sqlite gem.

    # remove
    gem 'sqlite3', '~> 1.3.6'
    
    # add
    gem 'pg', '~> 0.18.4' # check rubygems.org for the latest version
    

    Run bundle update to regenerate the Bundle.lock.

    3. Configure database.yml

    default: &default
      adapter: postgresql
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      timeout: 5000
    
    development:
      <<: *default
      database: 'my_app_development'
    
    # 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: 'my_app_test'
    
    # On Heroku you don't need the production section as it provides everything through 
    # ENV["DATABASE_URL"]
    # Heroku sets pretty good defaults as well so YAGNI.
    

    4. Commit and push

    0 讨论(0)
提交回复
热议问题