got error Binary was compiled with ‘CGO_E
NABLED=0’, go-sqlite3 requires cgo to work. This is a stub
panic: failed to connect database
两种解决方法
更换驱动
将官方的驱动:
import (
“gorm.io/driver/sqlite”
“gorm.io/gorm”
)
更换为:
import (
“github.com/glebarez/sqlite”
“gorm.io/gorm”
)
或者环境变量启用 cgo 支持
go env -w CGO_ENABLED=1