Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4238424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:54:11+00:00 2026-05-21T02:54:11+00:00

Guys I would really appreciate it if someone could help me with this. I

  • 0

Guys I would really appreciate it if someone could help me with this. I have a schema with 4 tables relevant to this question Books, Groups, ReadingList, Comments. A user of the system can join a group and add books to that group’s reading list. A group’s book list is represented by the table ReadingList:

ReadingList
-------------
Id (auto_increment)
ReadingListID
BookID (pk)
GroupID (pk)

BookID and GroupID are set up as a composite primary key to ensure no book can appear on a groups reading list twice. Both these fields have a fk defined to the relevant table Books/Groups. Now my problem comes when trying to set up a relationship between the Comments table and the ReadingList. The theory is that each unique entry in the ReadingList can have many comments (1..*) so basically one book on a groups reading list can have many comments associated with in. The Comments table looks like this:

Comments
-----------
Id (pk, auto_increment)
ReadingListID
UserName
Comment
TimeStamp

My logic is that a fk be set up from Comments (ReadingListID) to ReadingList (ReadingListID) but I am clearly flawed as I get a ‘no primary or candidate keys in referenced table’ error.

I have tried a variety of things like making ReadingListID & Id in the Comments table a composite key and making ReadingListID a pk in the ReadingList table etc, but I just can’t get my head round this. Please let me know if I haven’t been clear enough.

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:54:12+00:00Added an answer on May 21, 2026 at 2:54 am

    What you can do is use change the primary key of ReadingList from the composite (BookID+GroupID) to the ReadingListID column, then your FK will work. You can then create a unique constraint or index across the BookID+GroupID columns to enforce that data integrity.

    I’m confused, though, why you have an auto-increment on ReadingList (Id) which is separate from your ReadingListID column. Perhaps you should drop one or the other. In my mind, the way your schema seems to be set up, perhaps ReadingList.Id is the PK, and Comments.ReadingListID is a FK to that column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I give up and would really appreciate it if you guys could cast
This group has been very helpful, I really appreciate all the help. You guys
I really need help with interfaces in general... Any resources that you guys would
Ok guys, I know this is pretty a rare case but I really would
Ok guys, this question is related to my previous one. If I have set
What books would you guys recommend if one has been a java developer for
I know this a really stupid question. I've had a good few years experience
Hope you guys can help me out. I have information coming into a serial
I have this file call helloworld.txt: starthelloworld_some_text.jpgend starthelloworld_different_text.jpgend starthelloworld_another_different_one.jpgend and I would like Grep
another database structuring question, hope you guys dont mind :D i am having this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.