You might have to rule out cow`s milk protein allergy
since you say its related to dairy.
Give him plenty of water, fruit juices, vegetable soups, fresh fruits, vegetable like spinach, whole grain food etc.
Avoid rice based items, potatoes etc. Try to cut down on his formula milk. Instead of cerelac- give him home made food.
Please visit your Pediatrician
and get any anal fissures ruled out- as fissure is very painful and it sets up a cycle- due to pain child holds the stools, which in turn worsens the constipation
If he has a fissure, he needs a stool softener
and local anesthetic
gels for about 3weeks to help in complete healing.
Hope my answer helps you.
Wish your son good health.