Hi Sunflower,
Different forms of magnesium are more or less tolerable. You might try magnesium glycinate and see if that does better (assuming you were taking some other form previously). You might try taking it with calcium. It's generally recommended that the two be taken together. You might try starting at a low dose and working your way up. The single most common problem I see with people trying alternative treatments is they start at too high a dose. This isn't a drug. It's nutrition. If you need it, taking it should help rebuild your body. That means over time your body's ability to absorb things should improve some as underlying issues are addressed.
FWIW: Although I have taken magnesium in the past, I don't currently. If magnesium is a big problem for you, you can still work on addressing excess acidity by making dietary changes. I ate lots of lettuce for a long time. I no longer eat much lettuce but for many months if I skipped my bowl of lettuce more than 2 days in a row, I ended up with serious gut issues and also more lung inflammation and more coughing.
Good luck with this.