Although you may not get enough magnesium from your diet, it is rare to be deficient in magnesium. However, certain medical conditions can upset the body's magnesium balance. For example, an intestinal virus that causes vomiting or diarrhea can cause a temporary magnesium deficiency.