This is a complicated problem to solve. Fortunately for migraine sufferers, cannabis has show itself to be very effective in both preventing migraines from coming on, and easing the pain when they do come on. As with most cannabis applications, you will need to experience with different product options and combinations until you find what works best for you.
Here is a good place to start looking for potential solutions: https://www.hellomd.dev/learn/migraines
mark