Lack of exercise increases one of the risks that you MIGHT develop diabetes.
Exercising helps but DOES NOT guarantee that you won't develop diabetes.
Avoiding type 2 diabetes is all about managing the risk factors. Risk factors include poor diet, lack of exercise, obesity, age, and heredity. Some of these factors are in your control and some are not. (You can't prevent or change age and heredity). But - again - these are just RISK FACTORS and even people with a good, healthy diet CAN develop type 2 diabetes because of age or heredity issues. (There is also no food that you can avoid that will guarantee that you do not develop diabetes. And there is no food you can eat that will guarantee that you do get diabetes.)
BTW - "exercise" doesn't have to be a major work-out at the gym. Exercise is just your body in motion. In fact, WALKING is one of the most recommended "exercises" for people who have developed diabetes. Doing things like parking far away from buildings you are going into so that you have a longer walk into the store or into your job is "exercise". Walking down rows in stores even if you don't need anything in that row is "exercise".
So - no - you do not absolutely have to exercise to prevent diabetes. But, if you are not going to exercise, then you should pay more attention to what you eat and maintain a healthy body weight through diet.