Fixed foreign key bug