Question: Define the database structure, including tables, relationships, and any constraints. - Provide an Entity - Relationship Diagram ( ERD ) for the database design. -

Define the database structure, including tables, relationships, and any constraints.
-Provide an Entity-Relationship Diagram (ERD) for the database design.
- context Diagram
the data that i got
Users
Stores information about all users, including voters, administrators, and candidates.
user_id (Primary Key, Auto Increment)
national_id (Unique, Required)
full_name
email (Unique)
password (Hashed)
role (e.g., "voter", "admin", "candidate")
photo_id (Stores path to uploaded ID photo)
is_eligible (Boolean, Indicates voter eligibility)
Elections
Stores details about elections.
election_id (Primary Key, Auto Increment)
name
start_date
end_date
status (e.g., "ongoing", "completed")
Candidates
Stores candidate information.
candidate_id (Primary Key, Auto Increment)
election_id (Foreign Key to Elections)
user_id (Foreign Key to Users, references the candidate)
bio
votes (Default 0, Updated dynamically during vote tallying)
Votes
Stores cast votes.
vote_id (Primary Key, Auto Increment)
election_id (Foreign Key to Elections)
voter_id (Foreign Key to Users, references the voter)
candidate_id (Foreign Key to Candidates)
cast_at (Timestamp)
is_provisional (Boolean)
Results
Stores finalized election results.
result_id (Primary Key, Auto Increment)
election_id (Foreign Key to Elections)
candidate_id (Foreign Key to Candidates)
total_votes
Feedback
For app rating and feedback.
feedback_id (Primary Key, Auto Increment)
user_id (Foreign Key to Users)
rating (Integer, e.g.,15)
comments
Relationships
Users Votes: One-to-Many (A voter can vote only once in each election).
Elections Candidates: One-to-Many (Each election can have multiple candidates).
Elections Votes: One-to-Many (Votes are linked to specific elections).
Candidates Votes: One-to-Many (Votes are cast for candidates).
Elections Results: One-to-One (Each election has one result entry).
Constraints
Voter Registration
Unique constraint on national_id to avoid duplicates.
Validation of is_eligible before allowing registration completion.
Ballot Casting
A unique composite key on voter_id and election_id in the Votes table to ensure one vote per voter per election.
Vote Tallying
The system automatically calculates votes from the Votes table, grouping by candidate_id and election_id.
Results Reporting
Only authorized users (e.g., admins) can insert into or update the Results table.
Rating the App
Ensure rating is between 1 and 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!