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

Creating models does not work #5774

Closed
SHAGGYER opened this issue Oct 16, 2022 · 2 comments
Closed

Creating models does not work #5774

SHAGGYER opened this issue Oct 16, 2022 · 2 comments
Assignees
Labels

Comments

@SHAGGYER
Copy link

Hello,
I have some code to create a todo. but it doesnt work.

type Todo struct { ID uint gorm:"primary key;autoIncrement" json:"id"Title stringjson:"title"Done intjson:"done"Body stringjson:"body"`
}

app.Post("/api/todos", func(c *fiber.Ctx) error {
todo := &Todo{}

if err := c.BodyParser(todo); err != nil {
return err
}

err := db.Create(&todo).Error // does not work

if err != nil {
c.Status(http.StatusBadRequest).JSON(
&fiber.Map{"message": "could not create book"})
return err
}

var todos []Todo
db.Find(&todos)

return c.JSON(todos)
})`

i get the following error:

2022/10/16 22:12:37 C:/Users/xxx/go/src/go-todo-app/server/main.go:38 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RETURNING id' at line 1
[0.550ms] [rows:0] INSERT INTO todos (title,done,body) VALUES ('Testing',0,'Finish Tutorial') RETURNING id

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Oct 16, 2022
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@a631807682
Copy link
Member

duplicated of go-gorm/mysql#93

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

No branches or pull requests

3 participants