Bugs are an unavoidable aspect of mathematical programming (MP) modelling. In this paper we discuss the prevention and diagnosis of bugs in MP models. The topic is rarely addressed in the literature but is crucial to the success of modelling projects, especially for large models. We argue that finding a bug and understanding unexpected results (whether or not due to a bug) are very closely related activities. We identify different types of bugs and suggest practical strategies for dealing with each. Adopting procedures for prevention of bugs is essential, especially for large models. We outline the prevention strategies we have adopted and found successful for the MIDAS and MUDAS models.