You can help prevent getting type 2 diabetes by eating healthy and not becoming overweight, being overweight is the number one reason people develop the condition, exercise is always a good prevention
Unfortunately for those who develop type 1 diabetes, it is not something that is caused by being unhealthy, it is usually genetic and develops before the age of 25 in most cases.
You can also be diagnosed with type one if you have your pancreas removed to to illness such as cancer
The final way you can develop type one diabetes is by a virus which causes your immune system to attack your insulin producing cells