mesh rotation error after i attached the bones firstly , i create a toy with several boxes, then i create several bones

seconldly , i set the mesh's parent to any bone

and last, i found the body mesh's orientation changed by the bone, what's the problem with my model?
Once you've parented your mesh, you often need to corect the IK Pole Angle so that the mesh doesn't get twisted by the IK:

Also, always bend a bit the knees and elbows in Edit mode so that Blender knows how to bend these limbs once rigged: