【问题标题】:GORM and SQLite : auto increment don't workGORM 和 SQLite:自动增量不起作用
【发布时间】:2021-11-26 11:16:57
【问题描述】:

我有以下结构:

// Equipement
type Equipement struct {
   ID int gorm:"primaryKey;autoIncrement"
   IP string gorm:"not null"
   Username string gorm:"not null"
   AuthPass string gorm:"not null"
   AuthProtocol string gorm:"not null"
   PrivatePass string gorm:"not null"
   PrivateProtocol string gorm:"not null"
}

我想在我的 ID 上设置自动增量。但是当我执行 AutoMigrate() 时我什么都没有。

我看到了这个link,但我不想使用 gorm.Model,我想使用我自己的 ID。

下一张是我想要的..

【问题讨论】:

  • 什么是 gorm 版本?什么是分贝/方言?
  • GORM : v1.21.15 我使用 SQLite 数据库

标签: sqlite go go-gorm


【解决方案1】:

我了解 AutoIncrement 是您设置 PrimaryKey 时的默认设置。 尝试将 autoIncrement 更改为不为空。

 ID             uint   `gorm:"primaryKey; not null"`

https://gorm.io/docs/composite_primary_key.html#content-inner

【讨论】:

  • 这很好,我在另一台具有相同程序的计算机上进行。感谢您的宝贵时间。
猜你喜欢
  • 2021-10-13
  • 2013-05-25
  • 1970-01-01
  • 2015-08-06
  • 1970-01-01
  • 2017-12-30
  • 2013-10-13
  • 2015-11-22
  • 2023-03-21
相关资源
最近更新 更多