ActiveRecord的:: AdapterNotSpecified数据库配置不指定适配器 [英] ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

查看:382
本文介绍了ActiveRecord的:: AdapterNotSpecified数据库配置不指定适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Heroku的打开我的web应用程序工作正常,但当我用钢轨S(本地)我遇到了这个错误:

 的ActiveRecord :: AdapterNotSpecified数据库配置不指定适配器
 

这是为什么?

这是我的database.yml

 #PostgreSQL的。版本8.2及以上的支持。
#
#安装PG驱动程序:
#创业板安装PG
#在与自制OS X:
#创业板安装PG  -  --with-PG-配置=在/ usr / local / bin目录/ pg_config
#在与MacPorts的OS X:
#创业板安装PG  -  --with-PG-配置= /选择/ local / lib目录/ postgresql84 /斌/ pg_config
#在Windows上:
#创业板安装PG
#选择在Win32版本。
#安装PostgreSQL,并把它的/ bin目录的路径。
#
#配置使用的Gemfile
#宝石PG
#
默认:放大器;默认
  适配器:PostgreSQL的
  编码:UNI code
  #有关连接池的详细信息,请参阅导轨配置指南
  #http://guides.rubyonrails.org/configuring.html#database-pooling
  池:5
 

这是我的Gemfile:

 来源https://rubygems.org


创业板PG

创业板自举 - 萨斯,GT〜&; 3.1.1

#捆绑边缘轨道,而不是:创业板轨,github上:导轨/导轨
创业板导轨,4.0.3

#使用SCSS的样式表
创业板上海社会科学院护栏,GT〜&; 4.0.0

#使用Uglifier作为COM pressor对JavaScript资产
创业板uglifier','> = 1.3.0'

#使用的CoffeeScript的.js.coffee资产和意见
创业板咖啡轨,GT〜&; 4.0.0

#见https://github.com/sstephenson/execjs#readme更多的支持运行时
#创业板therubyracer',平台:红宝石

#使用jQuery的JavaScript库
创业板的jQuery护栏

#Turbolinks使得Web应用程序以下链接速度更快。了解更多:https://github.com/rails/turbolinks
创业板turbolinks

#构建JSON API的轻松。了解更多:https://github.com/rails/jbuilder
创业板的JBuilder,GT〜&; 1.2

组:DOC做
  #捆绑EXEC耙DOC:导轨产生下DOC / API的API。
  创业板SDOC,要求:假的
结束

组:生产做
  创业板rails_12factor,0.0.2
结束

#使用加载ActiveModel has_​​secure_password
#创业板bcrypt-红宝石','〜> 3.1.2

#使用麒麟作为应用服务器
#宝石'麒麟'

#使用Capistrano的部署
#创业板Capistrano的,群:发展

#使用调试器
#宝石调试,群:[:开发:测试]
 

解决方案

有关您的应用程序在本地工作,你需要:

  1. 你的机器上安装PostgreSQL
  2. 创建一个数据库为您的发展需要(我们称之为 my_app_development
  3. 更​​改的database.yml 来:

     默认:放大器;默认
      适配器:PostgreSQL的
      编码:UNI code
      #有关连接池的详细信息,请参阅导轨配置指南
      #http://guides.rubyonrails.org/configuring.html#database-pooling
      池:5
    
    发展:
      <<:*默认
      数据库:my_app_development
     

  4. 运行耙分贝:迁移

When I use heroku open my web app works fine but when I'm using rails s (localhost) I am running into this error:

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

Why is this?

This is my database.yml

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

And this is my gemfile:

source 'https://rubygems.org'


gem 'pg'

gem 'bootstrap-sass', '~> 3.1.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/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', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

解决方案

For you app to work locally you need to:

  1. Install Postgresql on your machine
  2. Create a database for your development needs (let's call it my_app_development)
  3. Change your database.yml to:

    default: &default
      adapter: postgresql
      encoding: unicode
      # For details on connection pooling, see rails configuration guide
      # http://guides.rubyonrails.org/configuring.html#database-pooling
      pool: 5
    
    development:
      <<: *default
      database: my_app_development
    

  4. run rake db:migrate

这篇关于ActiveRecord的:: AdapterNotSpecified数据库配置不指定适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆