我正在尝试获取一些旧代码来通过其单元测试。给我带来问题的测试在这里:
func Test1(t *testing.T){
//Code
testDevice := Device{
ID: 1,
Guid: "C6",
Name: "test device",
}
err := Dbmap.Insert(&testDevice)
So(err, ShouldBeNil)
//More code
}
当我运行时go test
,这会返回:
'sql: Scan error on column index 0: converting driver.Value type <nil> ("<nil>") to a int64: invalid syntax'
这很奇怪,因为我传递的是 1,一个整数。设备结构在这里定义:
type Device struct {
ID int64 `db:"id"`
Guid string
Name string
}
这是它插入的 Postgres 表的架构:
CREATE TABLE devices(
ID INTEGER,
Guid VARCHAR,
Name VARCHAR
);
我已经尝试使用该sql.NillInt64
类型,但这似乎并不能解决问题。感觉好像 gorp、go 或 postgres 以某种方式将整数解释为 nil。作为最终数据点,这一切都在各种 Docker 容器中运行,尽管我认为这个问题与 Docker 无关。有什么见解吗?