MCPcopy
hub / github.com/django/django / _check_on_delete

Method _check_on_delete

django/db/models/fields/related.py:1073–1160  ·  view source on GitHub ↗
(self, databases)

Source from the content-addressed store, hash-verified

1071 )
1072
1073 def _check_on_delete(self, databases):
1074 on_delete = getattr(self.remote_field, "on_delete", None)
1075 errors = []
1076 if on_delete == DB_CASCADE:
1077 errors.extend(
1078 self._check_on_delete_db_support(
1079 on_delete, "supports_on_delete_db_cascade", databases
1080 )
1081 )
1082 if on_delete == DB_SET_NULL:
1083 errors.extend(
1084 self._check_on_delete_db_support(
1085 on_delete, "supports_on_delete_db_null", databases
1086 )
1087 )
1088 if on_delete in [DB_SET_NULL, SET_NULL] and not self.null:
1089 errors.append(
1090 checks.Error(
1091 f"Field specifies on_delete={on_delete.__name__}, but cannot be "
1092 "null.",
1093 hint=(
1094 "Set null=True argument on the field, or change the on_delete "
1095 "rule."
1096 ),
1097 obj=self,
1098 id="fields.E320",
1099 )
1100 )
1101 elif on_delete == SET_DEFAULT and not self.has_default():
1102 errors.append(
1103 checks.Error(
1104 "Field specifies on_delete=SET_DEFAULT, but has no default value.",
1105 hint="Set a default value, or change the on_delete rule.",
1106 obj=self,
1107 id="fields.E321",
1108 )
1109 )
1110 elif on_delete == DB_SET_DEFAULT:
1111 if self.db_default is NOT_PROVIDED:
1112 errors.append(
1113 checks.Error(
1114 "Field specifies on_delete=DB_SET_DEFAULT, but has "
1115 "no db_default value.",
1116 hint="Set a db_default value, or change the on_delete rule.",
1117 obj=self,
1118 id="fields.E322",
1119 )
1120 )
1121 errors.extend(
1122 self._check_on_delete_db_support(
1123 on_delete, "supports_on_delete_db_default", databases
1124 )
1125 )
1126 if not isinstance(self.remote_field.model, str) and on_delete != DO_NOTHING:
1127 # Database and Python variants cannot be mixed in a chain of
1128 # model references.
1129 is_db_on_delete = isinstance(on_delete, DatabaseOnDelete)
1130 ref_model_related_fields = (

Callers 1

checkMethod · 0.95

Calls 5

extendMethod · 0.80
has_defaultMethod · 0.80
appendMethod · 0.45
get_fieldsMethod · 0.45

Tested by

no test coverage detected