A trainer can earn badges from many gyms, and a gym hands out badges to many trainers. That is a many-to-many relationship, and a single foreign key cannot represent it. The solution is a third table where each row is one link: one trainer, one gym, one date.