Magnesium hasn't made any difference to me. Also I drink lots of water and won't limit fluids to avoid needing to go.
It's at least twice a night and has been since pregnancy 30 years ago. You do learn to do it with one eye shut so you can go straight back to sleep.
I do think it's possible to get into a bad habit of just- in- case wees. This especially if you struggle to get back to sleep.
I remember when the children were small and waking me up and I had work next day, that sense of panic that you might not get back to sleep, or if you do you'll wake up again needing a wee. So you go just in case.
I'm retired now so no children or work to get up for and it takes the pressure off. I wake up naturally every couple of hours but often now I don't go to the bathroom and just turn over.