Can the sun cause a migraine?

Yes. Any strong stimulus can cause a migraine in a predisposed individual. Bright sunlight is not an unusual trigger for a migraine. Many migraine suffers where dark sunglasses to prevent migraines. For more info see:
A trigger. Bright sunshine exposure is a clear cut trigger for migraine in many susceptible people, and some pts wear sunglasses continually. However, there are other triggers, and best to try to prevent your headaches so this does not occur. Many successful interventions are available.