Typeorm 级联删除

lul*_*ezy 7 node.js typescript typeorm

删除我的实体时遇到问题,我有以下部分代码

@ManyToOne(type => Comment, comment => comment.replies, {
    onDelete: "CASCADE"
})
parent: Comment;
Run Code Online (Sandbox Code Playgroud)

@OneToMany(type => Comment, comment => comment.parent)
replies: Comment[];
Run Code Online (Sandbox Code Playgroud)

我曾尝试manager.remove(comment)

await manager
    .createQueryBuilder()
    .delete()
    .from(Comment)
    .where("id = :id", { id: comment.id })
    .execute();
Run Code Online (Sandbox Code Playgroud)

两者都不起作用,是不是做错了什么,我该怎么做,这是我的选择查询

let comment = await manager
    .createQueryBuilder(Comment, "comment")
    .leftJoinAndSelect("comment.user", "user")
    .where("comment.id = :id", { id: request.body.comment })
    .getOne();
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

UnhandledPromiseRejectionWarning: QueryFailedError: ER_ROW_IS_REFERENCED_2: Cannot delete or update a parent row: a foreign key constraint fails
Run Code Online (Sandbox Code Playgroud)

提前致谢。

lul*_*ezy 9

显然我必须删除所有表并进行新的迁移才能onDelete: "CASCADE"生效但有效