1

我正在尝试创建记录,但出现此错误。

[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)> 
4

1 回答 1

2

你的表结构是什么样的?

我猜你有一个复合主键,id列是它的一部分。Cassandra PRIMARY KEY 是唯一的,因此您必须为 upsert 提供完整的密钥。

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

[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: {}>

您似乎没有id在您的TopicPost.new陈述中提供价值,但我确实在您的评论中看到了它:

author_id: nil, id: nil, message: nil

尝试为id. 当然,如果没有看到您的 PRIMARY KEY 定义,可能还有其他必需的列,您没有为其提供值,而是从那里开始。

于 2016-05-24T19:41:04.447 回答