Error checking for IntegrityError