Magnesium is a secondary nutrients, as calcium and sulfur and it is involved in production of chlorophyll, which is essential in the process of photosynthesis. Without magnesium, the chlorophyll is not able to capture the sun's light energy needed in photosynthesis process.
The plant's roots absorb the mineral nutrients found in the soils they grow. If the amount of nutrients present in soil is not enough, fertilizers can be helpful. Sandy soils are not suited for keeping the nutrients within, while organic soils behave much better.
Also, pay attention to the levels of pH from the soil where the plant grows, since magnesium, which is a macronutrient, is less available in acidic soils. Adding lime to these kind of soils, can reduce its acidity.