Food attracts them:
Don’t put food scraps in your compost pile. Avoid putting any meat and dairy products in your compost pile at all. They are like a welcome mat for the rodents. Either make another closed container for meat and dairy scraps and an open container for leaves and grass clippings. Or else bury your kitchen scraps in the garden. Or bury them down below in your compost pile and cover them with lots of leaves and grass clippings.
Do not let the compost become shelter:
Keep your compost moist. The second most important things for rats and mice after food is, shelter. And what could be more attractive than a dry shelter with food scraps available in it. The best place for the rats to nest and reproduce. So how to stop that from happening. We keep the compost moist. Don’t add water! Because that will make it smelly and cause disease and infections. Unless its very dry outside, then a little water wouldn’t hurt. To keep the compost moist, turn the pile regularly, this keep the compost moist and less hospitable for the rats
Defend your compost:
You could also plant chicken wire around your compost pile. This will provide somewhat protection from the rodents because they will not be able to get to the pile in the first place. However you will have to find a net with very little spacing.
Another method is one such that works for some people and not for some. Plant mint around the compost containers. It is said that rats and mice hate the scent of mint. So it is ought to keep them away
Out of reach:
Another method is to have above ground containers. These are old garbage cans with tight fitting lids whose bottom have been cut off and they are fixed above deep holes in the ground. They don’t cook as fast as the above ground bins but they bring in the earthworms that can be happily added to the garden.