NestJs / Typeorm - null value in column "userId" of relation "Article" violates not-null constraint

98 Views Asked by At

I have 2 entities: Article and User. I defined a manyToOne relation in article, one user may have many articles. I also defined both the relation and the relationId column in the article schema:

relations: {
    user: {
        type: 'many-to-one',
        target: 'User',
        nullable: false,
        joinColumn: {
            name: 'userId',
        },
    },
},
relationIds: {
    userId: {
        relationName: 'user',
    },
},

I receive a CreateArticleDto convert it to an Article entity with an userId field. I even logged the value right before sending it to typeorm save, this was the result:

{
  title: 'article title',
  description: 'cool article',
  link: 'www.link-to-article.com',
  author: 'the guy who wrote',
  userId: '1134b652-fadb-44c9-8a5f-0f73bf6ac18f'
}

Showing that the userId is not null, but I still get the following error: ERROR [ExceptionsHandler] null value in column "userId" of relation "Article" violates not-null constraint

How can I fix this?

0

There are 0 best solutions below