thomaswang
V2EX  ›  问与答

请教 gorm 问题

  •  
  •   thomaswang · Nov 21, 2018 · 1439 views
    This topic created in 2755 days ago, the information mentioned may be changed or developed.
    // 重设列名
    type Animal struct {
        AnimalId    int64     `gorm:"column:beast_id"`         // 设置列名为`beast_id`
        Birthday    time.Time `gorm:"column:day_of_the_beast"` // 设置列名为`day_of_the_beast`
        Age         int64     `gorm:"column:age_of_the_beast"` // 设置列名为`age_of_the_beast`
    }
    
    // 使用 tag`primary_key`用来设置主键
    type Animal struct {
      AnimalId int64 `gorm:"primary_key"` // 设置 AnimalId 为主键
      Name     string
      Age      int64
    }
    

    如果需要给一个字段 重设列名 & 设置主键 该咋写?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:47 · PVG 13:47 · LAX 22:47 · JFK 01:47
    ♥ Do have faith in what you're doing.