为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 gorm 模型上定义字符串列表?

如何在 gorm 模型上定义字符串列表?

Go
幕布斯7119047 2022-11-23 19:26:30
这是我的模特type Ticket struct {    gorm.Model    PassengerName string         `json:"passenger_name"`    Price         uint64         `json:"price"`    Seat          pq.StringArray `gorm:"type:string[]" json:"seat"`}gorm.io/driver/postgres@v1.3.1/migrator.go:118 错误:类型“string[]”不存在(SQLSTATE 42704)
查看完整描述

2 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

postgre 中没有字符串数据类型。将字符串 [] 更改为文本 []



查看完整回答
反对 回复 2022-11-23
?
慕娘9325324

TA贡献1783条经验 获得超4个赞

这不是一个好方法。你应该为它做一个单独的表


门票表:


type Ticket struct {

    gorm.Model


    PassengerName string         `json:"passenger_name"`

    Price         uint64         `json:"price"`

    Seat          []Seat         `json:"seat" gorm:"foreignKey:SeatId"` }

座位表:


 type Seat struct {

    gorm.Modal


    SeatId  serial `json:seat_id`

    Seat    string `json:"seat"`}


查看完整回答
反对 回复 2022-11-23
  • 2 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号