Description
Describe the bug
A clear and concise description of what the bug is.
column with default null will genereate time.Time,which will cause 'unsupported Scan, storing driver.Value type into type *time.Time'
To Reproduce
Steps to reproduce the behavior, if applicable:
-
The code is
CREATE TABLE
t_org
(
id
bigint(20) unsigned NOT NULL COMMENT 'id',
name
varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'name',
domain
varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
created_at
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at
timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
deleted_at
timestamp NULL,
PRIMARY KEY (id
),
KEYt_org_deleted_at_IDX
(deleted_at
) USING BTREE,
KEYt_org_domain_IDX
(domain
) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='table';
goctl model mysql ddl -s .\db\core.sql -dir ./db
package main
import (
"context"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"issue/db"
)
func main() {
sqlConn := sqlx.NewMysql("root:123456@tcp(127.0.0.1:3306)/template?charset=utf8mb4&parseTime=true&loc=Local")
model := db.NewTOrgModel(sqlConn)
one, err := model.FindOne(context.Background(), 1)
if nil != err {
panic(err)
} else {
println(one.Id)
}
}
-
The error is
panic: sql: Scan error on column index 4, name "updated_at": unsupported Scan, storing driver.Value type <nil> into type *time.Time
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Environments (please complete the following information):
- OS: windows11
- go-zero version v1.5.3
- goctl version 1.5.2
More description
Add any other context about the problem here.