Fix inconsistent IDs in relation tables