【问题标题】:Error when running cmd <rake db:migrate> - "No connection pool with 'primary' found"运行 cmd <rake db:migrate> 时出错 - “没有找到‘primary’的连接池”
【发布时间】:2018-02-19 02:35:23
【问题描述】:

我正在尝试为我的 sinatra 应用程序设置 SQLite Db,但遇到了一个我无法弄清楚的错误。我查找了相关问题,但没有一个有帮助。

到目前为止,我已经运行了bundle exec rake db:create_migration NAME=create_budget 它在我的 db 文件夹中创建了一个迁移。

但是,当我运行 bundle exec rake db:migrate 时,我收到以下错误消息:

ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found.

我正在关注教程https://learn.co/lessons/sinatra-activerecord-setup

database.yml - 说明没有说要创建它,但在研究错误时,这似乎不断出现。作为一个学习者,这对我来说仍然很神奇,所以我不确定 activerecord 是否需要这个。

 # SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# 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:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

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

迁移:使用db:create_migration创建

# Database Migration
class CreateBudget < ActiveRecord::Migration[5.1]
  def change
    create_table :budget do |t|
      t.string :description
      t.string :amount
    end
  end
end

宝石文件:

# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

gem 'activerecord'
gem 'rake'
gem 'require_all'
gem 'sinatra'
gem 'sinatra-activerecord'
gem 'slim'
gem 'thin'

group :development do
  gem 'pry'
  gem 'shotgun'
  gem 'sqlite3'
  gem 'tux'
end

文件结构 - 不确定这是否有用

【问题讨论】:

  • 看来我需要先运行rake db:create。它要么从本教程中丢失,要么我忽略了它。运行时出现错误。如果提供修复程序,将更新。
  • 现在当我运行rake db:create 时出现以下错误ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: []. 想法?
  • 同样的问题,我还在努力解决,我一直在谷歌上搜索并逐页阅读。恼人的。无法查明问题

标签: ruby sqlite activerecord migration sinatra


【解决方案1】:

bundle exec rake db:create:all

【讨论】:

    猜你喜欢
    • 2013-03-08
    • 2015-05-24
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多