插入关系表多对多时出错
我正在尝试使用 typeORM 和 Nestjs 将关系数据保留在 mysql 数据库中,但它在数据库中明显显示错误
Entity:
@ManyToMany(()=> Stock, stock => stock.seals)
@JoinTable()
stock: Stock[];
Service:
var c = getConnection().getRepository(Seals).save(createSealDto)
return c
Error:
错误 [ExceptionsHandler] 无法添加或更新子行:外键约束失败 (
stocksystem
.stock_seals_seals
, CONSTRAINTFK_70140d58e95fbceed988b224e64
FOREIGN KEY (stockId
) 参考stock
(id
) ON DELETE CASCADE ON UPDATE CASCADE)
负载:
{"client":{"id":1},"stock":[{"id":1},{"id":1}],"price":398}
I'm trying to persist relational data in myql database with typeORM and nestjs but it's showing an error apparently in the database
Entity:
@ManyToMany(()=> Stock, stock => stock.seals)
@JoinTable()
stock: Stock[];
Service:
var c = getConnection().getRepository(Seals).save(createSealDto)
return c
Error:
ERROR [ExceptionsHandler] Cannot add or update a child row: a foreign key constraint fails (
stocksystem
.stock_seals_seals
, CONSTRAINTFK_70140d58e95fbceed988b224e64
FOREIGN KEY (stockId
) REFERENCESstock
(id
) ON DELETE CASCADE ON UPDATE CASCADE)
Payload:
{"client":{"id":1},"stock":[{"id":1},{"id":1}],"price":398}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论