简体   繁体   English

`retrieve_connection':没有模型的连接池(ActiveRecord :: ConnectionNotEstablished)

[英]`retrieve_connection': No connection pool for Model (ActiveRecord::ConnectionNotEstablished)

I have a simple Ruby script i use successfully locally to import a CSV file to my model. 我有一个简单的Ruby脚本,我在本地成功使用该脚本将CSV文件导入到我的模型中。 This works in development but fails in Production (Heroku) 这在开发中有效,但在生产中失败(Heroku)

I can't seem to get past the following error: 我似乎无法摆脱以下错误:

`retrieve_connection': No connection pool for Company (ActiveRecord::ConnectionNotEstablished) `retrieve_connection':公司没有连接池(ActiveRecord :: ConnectionNotEstablished)

open_csv_prod.rb

require 'csv'
require_relative 'helpers'
require 'active_record'
require 'rails'

# Connect to database
ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]

class Company < ActiveRecord::Base
print_memory_usage do
print_time_spent do


  #open the file
    filename = 'lib/assets/1/BasicCompanyData-2016-09-01-part1_5.csv' 
  # count how many rows? 
    line_count = `wc -l "#{filename}"`.strip.split(' ')[0].to_i
  # Print that result  
    puts "#{line_count}"

    count = 0


    CSV.foreach(filename, headers: true) do |row|
      Company.create! row.to_hash
      count += 1
      p "#{count}"
    end

  end
  end 
  end

heroku run ruby open_csv_prod.rb heroku运行ruby open_csv_prod.rb

This results in the reported error above. 这导致上面报告的错误。 I have no idea why Heroku would complain about a pool as this is listed when i check ActiveRecord::Base.configurations[Rails.env] in Heroku Rails console. 我不知道为什么Heroku会抱怨一个池,因为当我在Heroku Rails控制台中检查ActiveRecord :: Base.configurations [Rails.env]时,列出了该池。

I should say i have tried this with the following database configuration but it also fails because heroku stores database information in [DATABASE_URL]. 我应该说我已经尝试了以下数据库配置,但是由于heroku在[DATABASE_URL]中存储了数据库信息,所以它也失败了。

ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
host:     ENV['IP'],
username: ENV['USERNAME'],
password: ENV['PASSWORD'],
database: 'dbb_development'
)

It is possible i am trying to connect all wrong, if so i just need to write to my Company model in a ruby script executed in the terminal. 有可能我试图连接所有错误的设备,如果是这样,我只需要在终端中执行的ruby脚本中写入我的Company模型即可。

This is a longshot but, you said that heroku store the DB config info in a URL. 这是一个远景,但是,您说过heroku将数据库配置信息存储在URL中。 The following snippet is from the rails docs 以下代码摘自Rails文档

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionHandling.html http://api.rubyonrails.org/classes/ActiveRecord/ConnectionHandling.html

ActiveRecord::Base.establish_connection(
  "postgres://myuser:mypass@localhost/somedatabase"
)

Maybe you can connect like this: 也许您可以像这样连接:

ActiveRecord::Base.establish_connection(
  ENV['DATABASE_URL']
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveRecord :: ConnectionNotEstablished - 没有X的连接池 - ActiveRecord::ConnectionNotEstablished - No connection pool for X ActiveRecord::ConnectionNotEstablished: ActiveRecord::Base with mongoid 没有连接池 - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid ActiveRecord::ConnectionNotEstablished(未找到“主”连接池。) - ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) ROR - ActiveRecord::ConnectionNotEstablished: PublicActivity::ORM::ActiveRecord::Activity 没有连接池 - ROR - ActiveRecord::ConnectionNotEstablished: No connection pool for PublicActivity::ORM::ActiveRecord::Activity 呈现结果时,ActiveRecord::ConnectionNotEstablished(未找到具有“主要”的连接池。) - ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) when rendering results ActiveRecord::ConnectionNotEstablished:在登台时找不到“阅读”角色的“主要”连接池 - ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found for the 'reading' role on staging Rails:没有 ActiveRecord::Base 的连接池 - Rails: No connection pool for ActiveRecord::Base 关闭 Rails ActiveRecord 连接池 - Close Rails ActiveRecord Connection Pool {model name} 没有连接池 - No connection pool for {model name} 引发ConnectionNotFounded,“未找到带有&#39;#{spec_name}&#39;的连接池。”除非池LOCALHOST3000不起作用 - raise ConnectionNotEstablished, “No connection pool with '#{spec_name}' found.” unless pool LOCALHOST3000 not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM