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)
提前致谢。
| 归档时间: |
|
| 查看次数: |
12797 次 |
| 最近记录: |