IntegrityError handling in training and test