Your Question

I have the following Struct/Model

type TestTable struct {
    ID      uint `gorm:"unique;autoIncrement"`
    QuoteID uint `gorm:"primaryKey"`
}

If I auto migrate it with gorm wierd things happen: At first the auto migration doesn't work at all: "there can be only one auto column and it must be defined as a key". Gorm tries to set both columns to autoIncrement. As far as I know this shouldn't happen? I fixed this issue by setting autoIncrement to false on QuoteID. Everything seems to work fine, but now gorm alters the table on every migration and creates a new unique key every time. id_1, id_2, id_3, and so on. I reported this as a question because I am not sure if this is intended or not.

The document you expected this should be explained

I would expect it to be explained there: https://gorm.io/docs/models.html#Fields-Tags

Expected answer

I would expect from gorm to create only one autoIncrement column and don't create multiple unique keys.

Help is appreciated! Have a great day :)

Comment From: Placeblock

Still a Problem. Tried some stuff but nothing helped much.

Comment From: Sherlock-HJ

me too

Comment From: csymlou

me too

Comment From: a631807682

https://github.com/go-gorm/gorm/pull/6386