I know how to avoid the situation, but can't assist on how to fix once broke.
To avoid this you need to ensure on check out that the airline program is on the folio -adjust if nesessary. (If the miles still go to the wrong program, you have the folio to prove the mistake.)