encapsulate backendspecific validation def initself connection self connection connection def checkself kwargs return def checkfieldself field kwargs errors backends may implement a checkfieldtype method if hasattrself checkfieldtype and ignore any related fields not getattrfield remotefield none ignore fields with unsupported features dbsupportsallrequiredfeatures all getattrself connection features feature false for feature in field model meta requireddbfeatures if dbsupportsallrequiredfeatures fieldtype field dbtypeself connection ignore nonconcrete fields if fieldtype is not none errors extendself checkfieldtypefield fieldtype return errors encapsulate backend specific validation backends may implement a check_field_type method ignore any related fields ignore fields with unsupported features ignore non concrete fields
class BaseDatabaseValidation:
    

    def __init__(self, connection):
        self.connection = connection

    def check(self, **kwargs):
        return []

    def check_field(self, field, **kwargs):
        errors = []
        
        if (
            hasattr(self, "check_field_type")
            and
            
            not getattr(field, "remote_field", None)
        ):
            
            db_supports_all_required_features = all(
                getattr(self.connection.features, feature, False)
                for feature in field.model._meta.required_db_features
            )
            if db_supports_all_required_features:
                field_type = field.db_type(self.connection)
                
                if field_type is not None:
                    errors.extend(self.check_field_type(field, field_type))
        return errors