Migraines are caused by lots of different factors. Stress, anxiety, changes in hormones (especially in women just before their period), depression and excitement ahve all been linked to migraines.
There is a hormone called serotonin, and when levels of serotonin drop, this can make the blood vessels in your brain spasm (suddenly contract), and they get narrower. This can cause symptoms of flashing or blind spots. Soon after, the blood vessels widen, which is what is actually thought to cause the headache that comes with the migrane.
Some people find certain foods can trigger migranes, including alcohol, chocolate, cheese, citrus fruits like oranges or caffeine from tea or coffee. Seeing bright lights, flickering (like from a computer screen), being in stuffy or humid rooms, being tired or having a lack of sleep can all lead to migranes too.