Potassium and magnesium help. Eat bananas and dark, dark chocolate (upwards of 82%).
But, during pregnancy, they just happen
It really sucks. Make sure you're relaxing your leg when you get one. It's really really hard, because your reflex when you're in pain is to tense your muscle, but that makes it so much worse. You have to really, really concentrate on relaxing the muscles in your leg. Someone told me (maybe here? Maybe somewhere else?) to make sure that your feet are flat and pointing towards the ceiling (like you're standing on the ground, even though you're lying down).