PostgreSQL
 SQL >> Base de Dados >  >> RDS >> PostgreSQL

Corrigindo 'Specified postgresql for database adapter' no Rails

A correção é trocar a gem do SQLite pela do Postgres no seu Gemfile. Substitua este bloco:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'sqlite3'
  # 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

Por este:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'pg'
  # 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

Para desenvolvimento e teste você precisa de gem pg para o adaptador PostgreSQL em vez de gem sqlite3. Depois execute bundle install e o Gem::LoadError desaparece.

Não esqueça do database.yml

Trocar a gem resolve o erro de carregamento, mas a aplicação só conecta de fato depois de ajustar config/database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

Se o erro persistir após o bundle install, reinicie o servidor: o Rails mantém as gems carregadas em memória e não percebe a troca sem um restart.