Beego: How can i insert NULL in datetime field using orm?

Created on 15 Jun 2017  路  2Comments  路  Source: astaxie/beego

  1. What version of Go and beego are you using (bee version)?
    1.8.3

  2. What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/var/www/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build305098829=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
  1. What did you do?
    in my _DB_:
    i have my_table with field current_date DATETIME
    in _models.go_:
type My_table struct {
    Id              int
        Name              string
    Current_date    string `orm:"null"`
}
func UpdateMyTable() {
        o := orm.NewOrm()
    var table My_table
    table.Name = "Bob"
    id, err := o.Insert(&table)
}
  1. What did you expect to see?
    I need to insert NULL in current_date, but after insert i get this value instead '0000-00-00 00:00:00'
V2.0 areorm kinbug

Most helpful comment

@adel1ne
Hello, I want to know that is the issue solved now?
How to insert NULL into datetime type column?
I have the same issue

All 2 comments

@adel1ne
Hello, I want to know that is the issue solved now?
How to insert NULL into datetime type column?
I have the same issue

I have same issue when i using [email protected], is there a solution now?

https://github.com/astaxie/beego/blob/v1.11.1/orm/db.go#L376
https://github.com/astaxie/beego/blob/v1.11.1/orm/db.go#L185

When i insert a zero time, it will parse to the query like:

INSERT INTO `xx` (`other`,`my_time`) VALUES ('test',NULL)

This will cause failure, even though I set the default time in mysql.

Was this page helpful?
0 / 5 - 0 ratings