tortoise/tortoise-orm

on_delete should be required

开放

#1,801 创建于 2024年12月5日

 (3 条评论) (4 个反应) (0 位负责人)Python (333 个派生)batch import
enhancementgood first issue

仓库指标

星标
 (3,863 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Is your feature request related to a problem? Please describe. I encountered that when declaring ForeignKeyField on_delete = CASCADE, I believe that this is dangerous and in some scenarios may lead to undesirable consequences.

def ForeignKeyField(
    model_name: str,
    related_name: Union[Optional[str], Literal[False]] = None,
    on_delete: OnDelete = CASCADE,
    db_constraint: bool = True,
    null: bool = False,
    **kwargs: Any,
) -> "ForeignKeyRelation[MODEL] | ForeignKeyNullableRelation[MODEL]":

Describe the solution you'd like The best solution would be to make on_delete a mandatory parameter, I believe that actions with data should be explicit.

def ForeignKeyField(
    model_name: str,
    on_delete: OnDelete,
    related_name: Union[Optional[str], Literal[False]] = None,
    db_constraint: bool = True,
    null: bool = False,
    **kwargs: Any,
) -> "ForeignKeyRelation[MODEL] | ForeignKeyNullableRelation[MODEL]":

贡献者指南