我正在尝试从 sqlite 查询对象,但由于类型时间而出现此错误:
(sql: Scan error on column index 1: unsupported Scan, storing driver.Value type []uint8 into type *time.Time)
我的结构是:
type Timeline struct {
ID string `json:"id"`
Timestamp *time.Time `json:"timestamp"`
我的数据库是这样的:
CREATE TABLE timelines (id text, timestamp text, ...
样本行之一是:
('Locked in VR', '2018-03-17 10:50:59.548+01:00',...
有什么想法吗? 我应该在结构中添加一些东西吗?
Timestamp *time.Time `json:"timestamp" gorm:"time"`
最佳答案
我对gorm不熟悉,但应该不是datetime
类型的时间戳定义而不是text
?另外:当您标记 gorm:"time"
时,列名应该是 time
而不是 timestamp
,或者标记 gorm:"时间戳”
。但是您可以省略 gorm 标签。
为简单起见,您可以让 gorm 创建表:
db, err := gorm.Open("sqlite3", "test.db")
db.CreateTable(&Timeline{})
关于sqlite - 使用gorm的sqlite中的时间列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50258820/