Bug fix: foreign key assignment