Electrolytes in water does help. Maintaining your normal caffeine intake also helps.
Yes I find fasting a migraine trigger. But keeping everything else steady does help.
Try also doing your longer fasts lunch to supper, so eat a healthy lunch day 1, enough so you are not starving and headachy at bedtime, then fast through the next day but eat a light supper a few hours before bed to break your fast.