Magnesium supplementation -independent of the relative serum magnesium levels-, reduces both the frequency and severity of migraine and fibromyalgia pain.
Magnesium supplementation works in several ways:
Muscle relaxation through calcium channel blocking
Increasing the levels of serotonin and dopamine
Vasodilation (Reversing vasoconstriction and thus relaxing brain vessels)
Increasing the amount of oxygen supplied to the brain and muscles
Mitochondrial energy production regulation, reducing the effects of oxidative stress
Less pain-causing substances release
Calming the surface of the brain (making the brain less excitable)
Insulin resistance reduction
Chronic inflammation reduction
Lowering blood pressure
I recommend that you first increase the amount of magnesium you get through your food. Increase your consumption of vegetables (especially green leaved vegetables), fish, red meat, and nuts.
Reduce your coffee consumption to 1-2 small cups per day. Coffee lowers the magnesium levels and causes pain chronification.
Reduce your consumption of refined carbohydrates and sugars that cause insulin resistance and chronic inflammation.
If you still to continue to have pain you might consider taking a supplement prescribed by your doctor.