[英]Is gobuffalo able to generate my tables automatically?
I have this structure:我有这个结构:
type User struct {
ID int
CreatedAt int
UpdatedAt int
DeviceUniqueIdentifier string
Sessions []Session `has_many:"sessions"`
}
I have no idea how to export this in fizz, so I did so:我不知道如何在 fizz 中导出它,所以我这样做了:
buffalo pop generate model User
To my surprise, it actually generated a User and put a table in the database, but neither the table nor the structure are as expected.令我惊讶的是,它实际上生成了一个 User 并在数据库中放置了一个表,但无论是表还是结构都不是预期的。
Here is the new User struct:这是新的用户结构:
...
type User struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
...
Is there any way to generate passing some fields?有没有办法生成传递一些字段? Or is there a way to convert the structure to a table automatically?或者有没有办法自动将结构转换为表格?
There's a way to generate a model passing some fields:有一种方法可以生成传递一些字段的模型:
buffalo pop generate model User id:int device_unique_identifier
You have to add your columns definition after the name of the model.您必须在模型名称后添加列定义。 The column syntax allows you to give the column type (by default it's considered as a string).列语法允许您提供列类型(默认情况下,它被视为字符串)。
You'll have to add your has_many relation by hand though, relations are not yet supported by the generator.您必须手动添加您的has_many关系,但生成器尚不支持关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.