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

koalacxr picture koalacxr  路  3Comments

corvinusy picture corvinusy  路  3Comments

fieryorc picture fieryorc  路  3Comments

Ganitzsh picture Ganitzsh  路  3Comments

youtwo123 picture youtwo123  路  3Comments