Hamstring and Glute Cramps

For 4 to 5 months I have been unable to squat or deadlift consistently because of horrible hamstring and glute cramps that come with pushing it at all. Tons of foam rolling my hams and glutes can help for a limited time, but I need a suggestion for a more permanent solution.
Thanks in advance!

If you’re cramping, take some magnesium, you may be deficient in it.

Two large capsules/tablets usually do the trick for me. If you’re really deficient, you may need four or more capsules.

If it’s not a dietary defeciency as suggested, it could be synergistic dominance of the hamstrings and/or hip flexors (i.e. they are stronger than the glutes and essentially do the work the glutes should be doing.) Continue with the foam rolling, but also start to work the tissue of the hip flexors, as well as stretching. Make sure you’re glutes are firing properly and bring up their strength with some bodyweight glute activation work, while working in some hip mobility drills.