Gorm: How to add string that contains ';' to default value for gorm tags

Created on 12 Oct 2016  ·  1Comment  ·  Source: go-gorm/gorm

I want to let Query have a default equal 60;120 , so i write such code:

package main

import (
    "log"
    "math/rand"
    "time"

    _ "github.com/go-sql-driver/mysql"
    "github.com/jinzhu/gorm"
)

type J struct {
    ID    int
    Query string `gorm:"default:\"60;120\""`  // here gorm will report error because of ';' 
}

func main() {
    db, err := gorm.Open("mysql", "root:123456@/config?charset=utf8&parseTime=true&loc=Local")
    if err != nil {
        log.Println(err)
    }
    db.LogMode(true)
    db.AutoMigrate(&J{})
}

I know the reason why it can't work, but i don't know how to solve it if i still want to set default value as 60;120

>All comments

Maybe consider to change its default value with raw sql for this case?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imbaMF picture imbaMF  ·  15Comments

brunocassol picture brunocassol  ·  14Comments

feige84 picture feige84  ·  19Comments

ajays20078 picture ajays20078  ·  15Comments

MikeJinhua picture MikeJinhua  ·  22Comments