CQL Cassandra Missing mandatory PRIMARY KEY part id

2k Views Asked by At

I'm trying to create a record and I'm getting this error.

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

There are 1 best solutions below

2
On BEST ANSWER

What does your table structure look like?

I'm guessing that you have a composite PRIMARY KEY, and the id column is a part of it. Cassandra PRIMARY KEYs are unique, so you must provide the complete key for an upsert.

In looking at your code, specifically the commented-out portion, I do see a clue:

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

You don't appear to be providing a value for id in your TopicPost.new statement, but I do see it in your comment:

author_id: nil, id: nil, message: nil

Try providing a value for id. Of course, without seeing your PRIMARY KEY definition, there could be other required columns that you are not providing a value for, but start there.