Fix for a bug where we would sometimes use the wrong unique constraint to validate foreign key constraints.