提问人:Thiago Dias 提问时间:11/13/2023 更新时间:11/13/2023 访问量:22
NestJs / Typeorm - 关系“Article”的列“userId”中的空值违反了非 null 约束
NestJs / Typeorm - null value in column "userId" of relation "Article" violates not-null constraint
问:
我有 2 个实体:和 .我在文章中定义了一个关系,一个用户可能有很多文章。我还在文章架构中定义了 relation 和 relationId 列:Article
User
manyToOne
relations: {
user: {
type: 'many-to-one',
target: 'User',
nullable: false,
joinColumn: {
name: 'userId',
},
},
},
relationIds: {
userId: {
relationName: 'user',
},
},
我收到一个 将其转换为带有字段的实体。
我什至在将值发送到 typeorm 之前记录了该值,结果如下:CreateArticleDto
Article
userId
save
{
title: 'article title',
description: 'cool article',
link: 'www.link-to-article.com',
author: 'the guy who wrote',
userId: '1134b652-fadb-44c9-8a5f-0f73bf6ac18f'
}
显示 不是 null,但我仍然收到以下错误:userId
ERROR [ExceptionsHandler] null value in column "userId" of relation "Article" violates not-null constraint
我该如何解决这个问题?
答: 暂无答案
评论