MCPcopy
hub / github.com/tortoise/tortoise-orm / __init__

Method __init__

tortoise/fields/base.py:218–289  ·  view source on GitHub ↗
(
        self,
        source_field: str | None = None,
        generated: bool = False,
        primary_key: bool | None = None,
        null: bool = False,
        default: Any = None,
        db_default: Any = DB_DEFAULT_NOT_SET,
        unique: bool = False,
        db_index: bool | None = None,
        description: str | None = None,
        model: Model | None = None,
        validators: list[Validator | Callable] | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

216 def __set__(self, instance: Model, value: VALUE) -> None: ...
217
218 def __init__(
219 self,
220 source_field: str | None = None,
221 generated: bool = False,
222 primary_key: bool | None = None,
223 null: bool = False,
224 default: Any = None,
225 db_default: Any = DB_DEFAULT_NOT_SET,
226 unique: bool = False,
227 db_index: bool | None = None,
228 description: str | None = None,
229 model: Model | None = None,
230 validators: list[Validator | Callable] | None = None,
231 **kwargs: Any,
232 ) -> None:
233 if (index := kwargs.pop("index", None)) is not None:
234 if db_index is None:
235 warnings.warn(
236 "`index` is deprecated, please use `db_index` instead",
237 DeprecationWarning,
238 stacklevel=2,
239 )
240 db_index = index
241 elif db_index != index:
242 raise ConfigurationError(
243 f"{self.__class__.__name__} can't set both db_index and index"
244 )
245 if not self.indexable and (unique or db_index):
246 raise ConfigurationError(f"{self.__class__.__name__} can't be indexed")
247 if (pk := kwargs.pop("pk", None)) is not None:
248 if primary_key is None:
249 warnings.warn(
250 "`pk` is deprecated, please use `primary_key` instead",
251 DeprecationWarning,
252 stacklevel=2,
253 )
254 primary_key = pk
255 elif primary_key != pk:
256 raise ConfigurationError(
257 f"{self.__class__.__name__} can't set both primary_key and pk"
258 )
259 if null:
260 if pk:
261 raise ConfigurationError(
262 f"{self.__class__.__name__} can't be both null=True and pk=True"
263 )
264 if primary_key:
265 raise ConfigurationError(
266 f"{self.__class__.__name__} can't be both null=True and primary_key=True"
267 )
268 if primary_key:
269 db_index = True
270 unique = True
271 self.source_field = source_field
272 self.generated = generated
273 self.pk = bool(primary_key)
274 self.default = default
275 self.db_default = db_default

Callers

nothing calls this directly

Calls 2

has_db_defaultMethod · 0.95
ConfigurationErrorClass · 0.90

Tested by

no test coverage detected