fixed bug in foreign key assignment