【问题标题】:Rails with Redshift - how do I create relation?Rails 与 Redshift - 我如何创建关系?
【发布时间】:2017-06-19 09:23:42
【问题描述】:

在我的 Rails 应用程序中,我试图为我的一个模型获取 Redshift 存储。我有适当的设置,例如

class RedshiftBase < ActiveRecord::Base
  establish_connection :redshift_development
  self.abstract_class = true
end

class Books < RedshiftBase
  self.table_name = :books
end

所以我的Book.connection 返回有效的#&lt;ActiveRecord::ConnectionAdapters::RedshiftAdapter:0... 对象。我仍然不知道我从这里去哪里,所以我得到关系,每次我创建一个对象时都会更新 Redshift db(Book.new 返回PG::UndefinedTable: 到目前为止的错误)。

【问题讨论】:

  • 尝试测试books 表,如Book.connection.execute('select count(*) from books')books 有可能不在 public 命名空间中。
  • 问题是我无法在 RedShift 中创建有效的关系(不知道如何)。我可以做Book.connection.create_table(:books) 之类的事情,我会得到一个关系但这是一种方法吗?如何创建属性?
  • 究竟什么是“关系”?如果是表,你有没有使用 Active Record Migrations 创建它?
  • 是的,我进行了迁移,但运行它后,我的 redshift 数据库没有更新为新表
  • 所以你必须解决迁移问题。权限,错误的数据库,等等。

标签: ruby-on-rails postgresql amazon-redshift


【解决方案1】:

您是否尝试过使用这些宝石中的任何一个将其与 活动记录:

Rails 5 ActiveRecord Redshift Adapter

Rails 4 ActiveRecord Redshift Adapter


或手动连接:

Create Redshift Client Connection via PG

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    相关资源
    最近更新 更多