The short version is this: if you don't take caffeine regularly, then yes, maybe a strong cup of coffee will do the trick. But if you have frequent headaches and/or take caffeine on a regular basis, then avoiding caffeine is the best.
The problem is that your body gets used to the effects if you take too much of anything. This means two things: at best, the substance becomes ineffective; at worst, you develop a dependency on the substance and go into withdrawal if you stop taking it. This is why caffeine is both a treatment and a cause of migraines. The key takeaway is that moderation is your best friend, as usual. You can read more on this short but informative article by the American Migraine Foundation.
Well! It's not a proven method but some people would prefer caffeine as a cure for a hangover. There are other good methods you can follow while a migraine attack: