Skip to content

If the created_at field is not added, the db.Save() function will continue to perform insertion operations. #6134

@polly3d

Description

@polly3d

GORM Playground Link

This is a fake URL to prevent this bug from being overlooked: go-gorm/playground#1

Description

The data model:

type User struct {
	ID           uint
	Name         string
}

Here are the steps to reproduce:

// Create first record
db.Create(&User{})

// Fetch the first record
var user *User
db.First(&user)

// Save record
user.Name = "jinzhu 2"
db.Save(&user)

// Save again with the same data
// It will throw an error: Error 1062 (23000): Duplicate entry '1' for key 'users.PRIMARY'
user.Name = "jinzhu 2"
db.Save(&user)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions