foreign key loop fixed