ruby - ActiveRecord::AdapterNotSpecified 数据库配置没有指定适配器

标签 ruby postgresql activerecord heroku ruby-on-rails-4

当我使用 heroku open 我的网络应用程序工作正常但是当我使用 rails s (localhost) 时我遇到了这个错误:

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

这是为什么?

这是我的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

这是我的 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]

最佳答案

要让您的应用在本地运行,您需要:

  1. Install Postgresql在你的机器上
  2. Create a database满足您的开发需求(我们称之为 my_app_development)
  3. 将您的 database.yml 更改为:

    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. 运行 rake db:migrate

关于ruby - ActiveRecord::AdapterNotSpecified 数据库配置没有指定适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23336755/

相关文章:

ruby - 基于用户定义的输入构建动态 if 语句

java - 从 jruby 和 warbled jar 运行之间有什么区别 "under the hood"?

ruby - 非正统 cucumber ...在步骤定义中创建 Cucumber::Ast::Table

postgresql - PostgreSQL 中重叠间隔的最大计数

ruby-on-rails-3 - RSpec 中的动态定义方法抛出错误

Ruby:为什么这种使用 map 的方式会抛出错误?

sql - 如何自动增加postgres中的列?就像那个递增数字之后的一些固定文本

postgresql - 将 COUNT 值声明为变量 (PostgreSQL)

mysql - 优化返回数百条记录的 Rails 3.0 查询

ruby-on-rails - 这可以与 rails 中的 named_scope 一起使用吗?