code: def handle_integrity_error(cls, exception):
          
  
          m = re.match(cls.MYSQL_INSERT_ERROR_REGEX,
                       exception.statement)
  
          if not m:
              raise exception
  
          model = find_model_by_table_name(m.group('table'))
  
          if not model:
              raise exception
  
          m = re.match(cls.MYSQL_DUPLICATE_ENTRY_ERROR_REGEX,
                       exception.orig.args[1])
  
          if not m:
              raise exception
  
          entity = model.__name__
          eid = m.group('value')
  
          raise AlreadyExistsError(entity=entity, eid=eid)
docs: Handle integrity error exceptions.