go-sql-driver / mysql

Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
https://pkg.go.dev/github.com/go-sql-driver/mysql
Mozilla Public License 2.0
14.45k stars 2.3k forks source link

missing destination name scene_type in *[]*model.Resource #1626

Closed linxiang4200 closed 3 weeks ago

linxiang4200 commented 3 weeks ago

Issue description

I have a table named resource and have defined a struct for it. However, I now need to add a new field to the table, but when this field is not yet added to the struct definition in the code, running the code results in an error: "missing destination name scene_type in []model.Resource." ,even though I didn't use this field . How can I avoid this error? Since database changes and code changes are not deployed simultaneously, this could cause issues when the service goes live.

Example code

type Resource struct {
    Id            int          `db:"id" json:"id"`
    CompanyId     int          `db:"company_id" json:"companyId"`
    Pid           int          `db:"pid" json:"pid"`
    CreatorId     int          `db:"creator_id" json:"creatorId"`
    Size          int64        `db:"size" json:"size"`
    Width         int          `db:"width" json:"width"`
    Height        int          `db:"height" json:"height"`
    IsFolder      bool         `db:"is_folder" json:"isFolder"`
    Trashed       bool         `db:"trashed" json:"trashed"`
    Type          ResourceType `db:"type" json:"type"`
    Filename      string       `db:"filename" json:"filename"`
    Extension     string       `db:"extension" json:"extension"`
    Thumbnail     string       `db:"thumbnail" json:"thumbnail"`
    // SceneType     int          `db:"scene_type" json:"sceneType"`   //if I not add this it will be error,even though I didn't use this field 

}

Error log

missing destination name scene_type in *[]*model.Resource