There are a number of things you can do to prevent or minimise attack.
Firstly, try and sow seeds with gaps between them to avoid the need to thin seedlings as the roots grow and swell. This is because carrot fly are attracted to the smell released by carrot leaves when their foliage is crushed.
Grow varieties that are less susceptible to carrot fly such as ‘Resistafly’, ‘Fly Away’ and ‘Maestro’.
Some people plant rows of onions next to carrots in the belief that the smell given off by the onions whilst they are actively growing may deter or hide the scent of carrot leaves.
Choose a different place to grow carrots in each year using crop rotation just in case some of the larvae overwinter in the soil where carrots were previously grown.
Placing a barrier of insect-proof netting, 60cm to 90cm tall, around the crop can help keep carrot fly out.
Wait until the end of May to sow carrots and harvest before the end of August to help reduce the effects of carrot fly. This timing means it misses the first generation of eggs laid.
There are no pesticides available for use by the home gardener but there are some biological controls available by mail order for watering into the soil to help control the larvae.