Lower back pain during pregnancy is really a common problem, but the thing is, you don't necessarily need muscle relaxants for it. At 24 weeks, your back usually doesn't hurt from muscle spasms in the classical sense - it's more about your shifted center of gravity, stretched ligaments, and pressure from your growing uterus. So the medication might not actually address the root cause, just ease the symptom.
With midocalm and other muscle relaxants, the situation really is tricky. Some doctors prescribe them, thinking the risk is minimal, but there's quite a bit of research out there, and it's contradictory. Here's the thing that often gets overlooked: even if a drug is theoretically allowed at this stage, that doesn't mean it's right for you. At 24 weeks, your body reacts differently than it did in the first trimester, and there are always more individual contraindications than what's written in the instructions.
What actually helps and is safe: proper back support (a pregnancy belt or brace - lots of moms say it's literally a lifesaver), massage, special pregnancy exercises, a warm bath before bed. Magnesium, which your doctor prescribed, works through relaxation but by a different mechanism. If the pain is really unbearable, talk to your doctor about your specific situation - it might be worth getting a consultation with an osteopath or a physical therapist who specializes in pregnant patients. That'll give you results without the risk.