英文:
Create table using Go-Gorp fails to set column details
问题
尝试使用Gorp-Go ORM包创建表格。成功在MySql中创建了表格,但未能附加列详细信息。
type Data struct {
id int `db:"pid"`
name string `db:",size:50"`
}
Gorp钩子
Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
Dbm.CreateTablesIfNotExists()
Dbm是指向gorp.DbMap的指针。结果表格中的列名为pid和*,size:50*。我尝试过以下方式:
type Data struct {
id int `db:"pid"`
name string `db:"name:xyz,size:50"`
}
但结果的列名仍为*"name:xyz,size:50"*。
英文:
Trying to create the table using Gorp-Go ORM package. Was able to successfully create the table in MySql but failed to attach column details.
type Data struct {
id int `db:"pid"`
name string `db:",size:50"`
}
Gorp hook
Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
Dbm.CreateTablesIfNotExists()
Dbm is pointer to gorp.DbMap. The resultant table has pid and ,size:50 has name. Have tried with
type Data struct {
id int `db:"pid"`
name string `db:"name:xyz,size:50"`
}
Still the resultant column name is "name:xyz,size:50"
答案1
得分: 2
根据这个评论,size特性仍然只在dev分支中可用。
你可以通过显式设置maxsize来实现。例如:
dt := Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
dt.ColMap("xyz").SetMaxSize(50)
Dbm.CreateTablesIfNotExists()
....
英文:
According to this comment, the size feature is still available in only dev branch.
You can achieve this by explicitly setting maxsize though. Example:
dt := Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
dt.ColMap("xyz").SetMaxSize(50)
Dbm.CreateTablesIfNotExists()
....
答案2
得分: 1
我相信列名不需要 "name"。
尝试使用 db:"xyz,size:50"
。
英文:
I believe the column name doesn't require "name"
Try db:"xyz,size:50"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论