CQL Cassandra 缺少必需的 PRIMARY KEY 部分 id

CQL Cassandra Missing mandatory PRIMARY KEY part id

我正在尝试创建记录,但遇到此错误。

[40] pry(main)> a = TopicPost.new(topic_id: "professional_safety", pub_date: "5a612420-21e2-11e6-bdf4-0800200c9a66")
=> #<TopicPost topic_id: "professional_safety", pub_date: 5a612420-21e2-11e6-bdf4-0800200c9a66, publisher: nil, author_id: nil, id: nil, message: nil, name: nil, link: nil, shared_count: nil, prospect_score: nil, indico_score: nil, keywords: #<Set: {}>, updated_at: nil, created_at: nil, profile_image: nil, bio: nil, account_link: nil, twitter_handle: nil, favorite_count: nil, followers_count: nil, klout_score: nil, has_engagements: nil, is_retweet: nil, engaged_influencer_ids: #<Set: {}>, urls: #<Set: {}>, images: #<Set: {}>, feed_name: nil, feed_url: nil, description: nil, title: nil, batch_id: nil, score: nil, fcm: nil, scorelog: {}>
[41] pry(main)> a.save
Cql::QueryError: Missing mandatory PRIMARY KEY part id
from /home/blau08/.rvm/gems/ruby-2.1.2/gems/cql-rb-2.0.4/lib/cql/client/client.rb:545:in `execute'
[42] pry(main)> 

你的 table 结构是什么样的?

我猜您有一个复合 PRIMARY KEY,id 列是其中的一部分。 Cassandra PRIMARY KEY 是唯一的,因此您必须为更新插入提供完整的密钥。

在查看您的代码时,特别是注释掉的部分,我确实看到了一个线索:

[40] pry(main)> a = TopicPost.new(topic_id: "professional_safety", pub_date: "5a612420-21e2-11e6-bdf4-0800200c9a66")
=> #<TopicPost topic_id: "professional_safety", pub_date: 5a612420-21e2-11e6-bdf4-0800200c9a66, publisher: nil, author_id: nil, id: nil, message: nil, name: nil, link: nil, shared_count: nil, prospect_score: nil, indico_score: nil, keywords: #<Set: {}>, updated_at: nil, created_at: nil, profile_image: nil, bio: nil, account_link: nil, twitter_handle: nil, favorite_count: nil, followers_count: nil, klout_score: nil, has_engagements: nil, is_retweet: nil, engaged_influencer_ids: #<Set: {}>, urls: #<Set: {}>, images: #<Set: {}>, feed_name: nil, feed_url: nil, description: nil, title: nil, batch_id: nil, score: nil, fcm: nil, scorelog: {}>

你似乎没有在你的 TopicPost.new 声明中为 id 提供价值,但我确实在你的评论中看到了它:

author_id: nil, id: nil, message: nil

尝试为 id 提供一个值。当然,在没有看到您的 PRIMARY KEY 定义的情况下,可能还有其他您没有为其提供值但从那里开始的必需列。