Is it safe to take medication for migraine while pregnant?

Depends. Many of the narcotic-based pain medications are relatively safe (e.g. Fda category b/c). Many of the anti-migraine meds (e.g. Triptans/imitrex) are in the same category as well. Most of the prophylactic (e.g. Taking something for prevention) medications (e.g. Beta blockers) are pretty safe. As always, consult with your provider before taking anything.
Yes if appropriate. Occasional use of usual pain meds is safe during pregnancy. Frequent or high dose complex medications may be dangerous to the fetus. Your OB should help with appropriate treatment regimen.