简体   繁体   English

动态子类化和ActiveRecord建立与PostgreSQL数据库的连接

[英]Dynamic Subclassing and ActiveRecord establish_connection with PostgreSQL database

I'm trying to create a utility to copy a subset of records from a single table of one PostgreSQL database to that same table in another PostgreSQL database. 我正在尝试创建一个实用程序,将记录的子集从一个PostgreSQL数据库的单个表复制到另一个PostgreSQL数据库的同一表。 I'm doing this with dynamic subclassing, but it's not working: it raises the error "xxx database is not configured" (where xxx is my database URL, something like "postgres://username:password@computername:5432/databasename". I know the URL is good because I copied it from my Heroku configuration and I am able to access the database from pgAdmin3 on my local machine. Here's the code: 我正在使用动态子类进行此操作,但无法正常工作:它引发错误“未配置xxx数据库”(其中xxx是我的数据库URL,类似“ postgres:// username:password @ computername:5432 / databasename”)我知道URL是好的,因为我是从Heroku配置中复制的,并且能够从本地计算机上的pgAdmin3访问数据库。

puts "Enter the database URL"
url = gets.chomp
db_conn = Class.new(ActiveRecord::Base) do
  establish_connection url
end

Support for establish_connection(url) was added in Rails 3.2; 在Rails 3.2中添加了对created_connection(url)的支持; I was running Rails 3.1.3. 我正在运行Rails 3.1.3。

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

相关问题 Rails无法使用ActiveRecord :: establish_connection连接到数据库 - Rails cant connect to database with ActiveRecord::establish_connection 拦截ActiveRecord建立连接初始化过程 - Intercept ActiveRecord establish_connection initialization process 了解establish_connection如何在ActiveRecord中工作 - Understanding how establish_connection works in ActiveRecord 建立连接':数据库配置指定不存在的mysql2适配器(ActiveRecord::AdapterNotFound) - establish_connection': database configuration specifies nonexistent mysql2 adapter (ActiveRecord::AdapterNotFound) 无法打开rails console:生成数据库未配置,establish_connection引发ActiveRecord :: AdapterNotSpecified - Can't open rails console: production database not configured, establish_connection raises ActiveRecord::AdapterNotSpecified 在ActiveRecord模型上使用Establishment_connection时,AdapterNotSpecified - AdapterNotSpecified when using establish_connection on ActiveRecord model 测试和建立连接 - testing and establish_connection 用rails查询外部数据库。 抽象类+建立连接? - Query external database with rails. Abstract Class + establish_connection? 如何在Rails中与多个数据库并行建立连接? - How to establish_connection with more than one database in parallel in Rails? 建立连接和耙任务在一起的问题 - issue with establish_connection and rake task together
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM