Massive Headaches

Everytime I get my period I get really bad headaches that make me physically sick and I can’t do anything except lie in bed or sleep. I don’t know what to do to prevent these? My period is pretty irregular and always has been so I can’t take pills when I know it’s starting because I usually don’t.