How can i set mysql column to be longtext since struct type sting is 255 varchar?
use tags, e.g.:
type MyStruct struct {
...
LongField string `sql:"type:text;"`
...
}
You could change the string length with sql:"size:999999" also
Hi Jay,
LongField string sql:"type:text;"
is not working.
When I do
dbmap.AddTableWithName(Post{}, "posts").SetKeys(true, "Id")
type Post struct {
Id int64 `db:"post_id"`
Created int64
Title string `form:"Title"`
Body string `sql:"type:text;"`
}
func initDb() *gorp.DbMap {
// connect to db using standard Go database/sql API
// use whatever database/sql driver you wish
//db, err := sql.Open("sqlite3", "/tmp/post_db.bin")
db, err := sql.Open("mysql", "user:pass@/martini")
checkErr(err, "sql.Open failed")
// construct a gorp DbMap
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}
// add a table, setting the table name to 'posts' and
// specifying that the Id property is an auto incrementing PK
dbmap.AddTableWithName(Post{}, "posts").SetKeys(true, "Id")
// create the table. in a production system you'd generally
// use a migration tool, or create the tables via scripts
err = dbmap.CreateTablesIfNotExists()
checkErr(err, "Create tables failed")
return dbmap
}
@goors Work for my at least for MySQL by using
`sql:"type:text"`
Most helpful comment
use tags, e.g.: