Removing a candidate from an office deletes all of that candidate's AMA questions, even if they're still in other races. The culprit is likely this line:
|
" REFERENCES " + db_name + ".`candidates` (`rcs_id`)" + |
When someone is removed from an office, a row in candidates is deleted. AMA questions are configured to cascade delete when that happens. However, this is wrong since candidates can be in multiple races. AMA questions should have a foreign key to candidate_data instead of candidates.