title: [Learning Notes][Golang] Solving the "undefined: sql.NullTime" Error When Using go-pg on Heroku
published: false
date: 2021-11-05 00:00:00 UTC
tags:
canonical_url: http://www.evanlin.com/go-heroku-go-version/
---

## Preface:
Recently, I'm modifying a [LINE Bot](https://dev.to/evanlin/xue-xi-xin-de-golang-shou-yang-lai-kai-shi-gai-line-ptt-query-bot-18o6-temp-slug-5979594) and replacing the MongoDB, which is no longer supported by Heroku, with PostgreSQL. I wanted to add free PostgreSQL, but I encountered some problems. Let's write down the related learning.
## Golang + ORM = Go-PG
I chose a package:
#### [https://github.com/go-pg/pg](https://github.com/go-pg/pg)
But after writing it, I found that it could compile locally, but it would crash when deployed to Heroku.
## error `undefined: sql.NullTime #59`
remote: # github.com/go-pg/pg/v10/orm
remote: vendor/github.com/go-pg/pg/v10/orm/table.go:41:40: undefined: sql.NullTime
remote: gopkg.in/mgo.v2/internal/scram
According to the following issue [https://github.com/guregu/null/issues/59](https://github.com/guregu/null/issues/59), the solution is to upgrade to go1.13.
go1.13 is enough
go1.13 is enough
go1.13 is enough
## Force Heroku to use a newer version ( > Go 1.12 )
Argh~~~ Isn't my Go local already upgraded to 1.17.2? How come?
remote: Detected go modules via go.mod
remote: ----->
remote: Detected Module Name: github.com/kkdai/linebot-ptt-beauty
remote: ----->
remote: !! The go.mod file for this project does not specify a Go version
remote: !!
remote: !! Defaulting to go1.12.17
remote: !!
remote: !! For more details see: https://devcenter.heroku.com/articles/go-apps-with-modules#build-configuration
remote: !!
remote: -----> Using go1.12.17
remote: -----> Determining packages to install
Here comes the problem….
No matter how new the Golang version is in your `go.mod`, Heroku will still use `go 1.12`
# force heroko to use go > 1.12
Refer to this stackoverflow
[https://stackoverflow.com/questions/56968852/specify-go-version-for-go-mod-file](https://stackoverflow.com/questions/56968852/specify-go-version-for-go-mod-file)
module somemodule
// +heroku goVersion go1.14
go 1.14
require (
// ...
)
If you want to use the latest version of Go 1.17.2, change it to
// +heroku goVersion go1.17
go 1.17
That's all.
# Other Links
- https://github.com/go-pg/pg/issues/445
- https://pg.uptrace.dev/
- https://devcenter.heroku.com/articles/getting-started-with-go?singlepage=true
Top comments (0)