Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pq: null value in column "favorites_count" of relation "articles" violates not-null constraint #5

Open
Msksgm opened this issue Jan 2, 2022 · 0 comments

Comments

@Msksgm
Copy link

Msksgm commented Jan 2, 2022

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

query := `
INSERT INTO articles (title, body, description, author_id, favorites_count, slug)
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, created_at, updated_at
`
args := []interface{}{
article.Title,
article.Body,
article.Description,
article.Author.ID,
article.FavoritesCount,
article.Slug,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant