Home > Net >  Questions with multiple choices database schema design
Questions with multiple choices database schema design

Time:12-11

Let's say we want to create a quiz application, where a user can create a quiz with the following characteristics:

  • Users can select questions for their quiz from a set of predefined questions.
  • Each question can have multiple options (choices); 2, 3, 5, 6, 9, it doesn't matter.
  • The questions and it's choices are added by the admins (through Django Admin API)

I have come up with a fairly simple schema design:

enter image description here

This is what's happening in the schema design above:

  • Each Question can have multiple choices
  • The QA maps the question to the answer selected by the user who did/took the quiz
  • Each submitted quiz can have multiple questions together with their answers

One of the downsides of this approach is that I can map questions to the answers which do not belong in the choices list of that particular question. For example, I create two questions;

  1. Are you Married?
  2. What is your favorite drink?

For the first question, I have the following options:

  1. Yes
  2. No

And for the second question, I have the following choices:

  1. Water
  2. Soda
  3. Fresh Juice

From the Django Admin API, I can map the first question; Are you married? to the choice of the second option; soda

How can I avoid this? And what other downsides do you see with this approach? Is there a better way to design this kind of schema???

I am using Django for this particular project.

EDIT: As you can see in the image below

  • Related