Ruby on rails 尽管I';我没有在我的gem文件中使用PG gem,并且database.yml不';不包括任何Postgresql引用

Ruby on rails 尽管I';我没有在我的gem文件中使用PG gem,并且database.yml不';不包括任何Postgresql引用,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我从我的机器上删除了postgres brew rm postgresql --force rm -rf /usr/local/var/postgres 我创建了一个新的rails应用程序。这是我的标准文件 source 'https://rubygems.org' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' gem 'sqlite3' gem 'puma', '~> 3.0' gem 'sass-rails', '~> 5.0' gem

我从我的机器上删除了postgres

brew rm postgresql --force
rm -rf /usr/local/var/postgres
我创建了一个新的rails应用程序。这是我的标准文件

source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'

group :development, :test do
  gem 'byebug', platform: :mri
end

group :development do
  gem 'web-console'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
然后

虽然我没有在我的gem文件中指定任何pg gem,但在尝试访问localhost时出现了错误

> Specified 'postgresql' for database adapter, but the gem is not loaded. 
> Add `gem 'pg'` to your Gemfile 
> (and ensure its version is at the minimum required by ActiveRecord).
> Extracted source (around line #176):

require path_to_adapter
rescue Gem::LoadError => eraise Gem::LoadError, 
"Specified '#{spec[:adapter]}' for database adapter, 
but the gem is not loaded. 
Add `gem '#{e.name}'` to your Gemfile   
(and ensure its version is at the minimum required by ActiveRecord)."
rescue LoadError => eraise LoadError,  
"Could not load '#{path_to_adapter}'. 
Make sure that the adapter in config/database.yml is valid. 
If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3'     
add the necessary adapter gem to the Gemfile.", e.backtrace
end
这是我的database.yml文件,它也不包含任何postgres

# 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
#SQLite版本3.x
#gem安装sqlite3
#
#确保在gem文件中定义了SQLite 3 gem
#gem'sqlite3'
#
默认值:&默认值
适配器:sqlite3
游泳池:5
超时:5000
发展:

在database.yml文件中,您仍然将postgres列为适配器。一旦您更改了database.yml以反映您没有使用postgres这一事实,您将需要运行
rake db:drop db:create db:migrate

我也有同样的问题

在控制台中写入:

echo$DATABASE\u URL 如果结果是:

Postgresql://user:password@本地主机/数据库 在您的.bash_配置文件或.profile中查找

导出数据库\u URL=“postgresql://user:password@本地主机/数据库“

评论这句话,让我感到高兴

读这里

第3.5节


“当提供重复的连接信息时,环境变量(DATABASE_URL)将优先”

my DATABASE.yml不包括任何postgres引用。重新编辑了我的问题并包含了yml内容我运行了rake db:drop db:create db:migrate
,并得到了错误rake中止!Gem::LoadError:为数据库适配器指定了“postgresql”,但未加载Gem。将
gem'pg'
添加到您的gem文件中(并确保其版本为ActiveRecord要求的最低版本)。
# 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