Fixes an error in foreignKey handling