You may be taking too much or taking the wrong type of magnesium. Try magnesium glycinate which does not usually affect the gastrointestinal system as much. Speak to your doctor if the diarrhea persists.