A perfectly straight back isn't actually ideal for squats, and that's probably part of your problem. You need some natural forward lean from the hips, not total rigidity. What does matter is keeping your spine neutral - meaning it follows its natural curve without hyperextending or rounding it. If you're forcing absolute verticality, you're putting weird tension on your lower back.
The pain almost always comes from a combo: lack of mobility in your ankles or hips, weak core, or just a position that doesn't work for your body. Try actually dropping the weight (or do bodyweight squats), keep your knees tracking over your feet, and let your chest go a bit forward. Some people find it helpful to do shallower squats while they fix their movement pattern. If your ankles are tight, that forces you to compensate with your lower back too.
If the pain sticks around even after you fix this stuff, there might be something else going on that means you need to skip deep squats for a while and just work on core strengthening. But before you get there, focus on technique without load and how your body actually moves, not how you think it should look.