charset=utf8mb4 in gorm dsn resulting double insert on DB using db.Create()

39 views Asked by At

So I run into problem when trying to insert a single data to database record using gorm. the problem is the data is inserted twice so i get double insert in the db

my insert logic is like this

func Store(c *fiber.Ctx) error {
    post := models.Post{Title: "One", Slug: "one", Body: "one"}
    models.DB.Create(&post)
    return nil
}

and when i try to remove the the charset=utf8mb4 form dsn the problem is gone, I don't know why. why it that happen?

// the old one
dsn = "root:root@tcp(127.0.0.1:3306)/go_journal?charset=utf8mb4&parseTime=True&loc=Local"

// the new one
dsn = "root:root@tcp(127.0.0.1:3306)/go_journal?parseTime=True&loc=Local"
0

There are 0 answers