You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Your Question
I have the following Struct/Model
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 :)
The text was updated successfully, but these errors were encountered: