1class BaseDatabaseValidation:
2 """Encapsulate backend-specific validation."""
3
4 def __init__(self, connection):
5 self.connection = connection
6
7 def check(self, **kwargs):
8 return []
9
10 def check_field(self, field, **kwargs):
11 errors = []
12 # Backends may implement a check_field_type() method.
13 if (
14 hasattr(self, "check_field_type")
15 and
16 # Ignore any related fields.
17 not getattr(field, "remote_field", None)
18 ):
19 # Ignore fields with unsupported features.
20 db_supports_all_required_features = all(
21 getattr(self.connection.features, feature, False)
22 for feature in field.model._meta.required_db_features
23 )
24 if db_supports_all_required_features:
25 field_type = field.db_type(self.connection)
26 # Ignore non-concrete fields.
27 if field_type is not None:
28 errors.extend(self.check_field_type(field, field_type))
29 return errors