Fix foreign keys bug