给定以下伪 cql 表结构:
CREATE TABLE searches (
category text,
timestamp timestamp,
no_of_searches int,
avg_searches double,
PRIMARY KEY((category, timestamp), no_of_searches)
);
以及以下 Rails Cequel 模型:
class Search
include Cequel::Record
# Table columns
key :category, :text
key :timestamp, :timestamp
key :no_of_searches, :int
column :avg_searches, :double
end
当我尝试使用以下方法同步模型时:
rake cequel:migrate
抛出以下 rake 错误:
rake aborted!
Cequel::InvalidSchemaMigration: Existing partition keys category,timestamp differ from specified partition keys timestamp
我正在尝试使用分区键使上述 Rails 模型与上表同步,尽管它指出两组键是不同的。我尝试过以相同的顺序定义键,但没有成功。
我的目标是获得预定义的数据库表,其中分区键与 Rails 模型一起使用。任何帮助将不胜感激!
最佳答案
key
方法支持选项哈希作为第三个参数。选项哈希添加了对已定义键的进一步支持,例如 order
和 partitioning
。
根据给定的表定义,这意味着您的表列将如下所示:
# Table columns
key :category, :text, { partition: true }
key :timestamp, :timestamp, { partition: true }
key :no_of_searches, :int
column :avg_searches, :double
不幸的是,这没有记录在 Cequel README 中,但它记录在代码中,可以找到 here .
关于ruby-on-rails - 在 Cassandra 的 Rails 中定义表复合主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25975675/