简体   繁体   English

gobuffalo 是否能够自动生成我的表格?

[英]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.

相关问题 CakePHP可以从Model上的_schema属性生成我的数据库表吗? - Can CakePHP generate my database tables from the _schema attribute on the Model? 在 BigQuery 中自动创建表 - Automatically creating tables in BigQuery 能够生成UUID,但无法将其插入数据库 - Able to generate UUID but was not able to insert the same into database 自动为数据库中的列生成值 - Automatically generate value for a column in database 我无法更改“表格列”的状态。 表的列名是“数字”。 这与我的 controller 中的输入“表”匹配 - I am not able to change the status of a “Tables column”. column name of Table is 'number'. which is matching to my input 'table' in my controller 由于此错误,我无法在我的数据库中更新或删除这两个表: - I am not able to update or drop these two tables in my database because of this error: 当系统日期和时间到到期日期时,如何使数据库表自动更新? - how can I make my database tables be automatically updated when the system date and time reaches a due date? SchemaCrawler无法找到MSSQL表 - SchemaCrawler not able to find MSSQL tables Wordpress 自动删除整张表 - Wordpress automatically deletes entire tables 如何使用JPA从1自动生成id? - How to automatically generate id from 1 with JPA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM