@yunewild
I don’t have an explanation for your coffee cure but if you get migraines often, it may be worth to try a magnesium supplement (e.g. magnesium citrate). There are lots of medical literature describing the role of magnesium in migraine prevention.