DEV Community

Evan Lin
Evan Lin

Posted on • Originally published at evanlin.com on

[Golang] Fixing "undefined: sql.NullTime" Errors with go-pg on Heroku

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/
---

![image-20211107005949431](http://www.evanlin.com/images/2021/image-20211107005949431.png)

## 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`

Enter fullscreen mode Exit fullscreen mode

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.

Enter fullscreen mode Exit fullscreen mode

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?

Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

// +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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)