Babies should be paternity tested at birth BUT sexually active men should be required to put their DNA into a paternity database.
All babies should be paternity tested at birth. If you did donor conception you can tell the hospital that. This would also cause fertility clinics to tone down their lying. This would prevent female infidelity, or at the very least cause woman cheaters to use protection. No man should be stuck in what is essentially a forced adoption. And no child should grow up with a false family history. These are all good things.
And also all sexually active straight/bi men should have to register their DNA. The baby would then be tested against the database. Gay men and celibate men won’t have to register because of course not all men are causing this problem. But if you get caught unregistered when you should be you get treated like a draft dodger. This would allow every baby to be DNA tested for who their father actually is. The named father wouldn’t have to show up for a test or act like he doesn’t trust his wife by submitting to the test- it would just automatically happen. The baby would know their lineage and the right father would be assigned to the baby.