go-realworld
go-realworld copied to clipboard
pq: null value in column "favorites_count" of relation "articles" violates not-null constraint
When I called the bellow api , this error of pq: null value in column "favorites_count" of relation "articles" violates not-null constraint
is happend.
curl --location --request POST 'http://localhost:6001/api/v1/articles' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNhbXBsZUBlbWFpbC5jb20iLCJpZCI6MX0.SZBUfkdrOBlmomrYzqNfjMBcjL9n8iwr948RsgJok1U' \
--data-raw '{
"article": {
"title": "title",
"description": "description",
"body": "body"
}
}'
I think this bellow query is not correct, because the col of favorites_count
is not included in the artcle table.
When I deleted favorites_count
and $6
and article.FavoritesCount
, it is workd correctly
https://github.com/0xdod/go-realworld/blob/d0c70558dd71a0dcd2513e041679a55daab9165c/postgres/article.go#L170-L183