Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gorm - AutoMigrate creates duplicate Unique Keys #6739

Closed
Placeblock opened this issue Dec 10, 2023 · 4 comments
Closed

Gorm - AutoMigrate creates duplicate Unique Keys #6739

Placeblock opened this issue Dec 10, 2023 · 4 comments
Assignees
Labels
type:question general questions

Comments

@Placeblock
Copy link

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 :)

@Placeblock Placeblock added the type:question general questions label Dec 10, 2023
@Placeblock Placeblock reopened this Dec 11, 2023
@Placeblock
Copy link
Author

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

@Sherlock-HJ
Copy link

me too

1 similar comment
@csymlou
Copy link

csymlou commented Jan 31, 2024

me too

@a631807682
Copy link
Member

#6386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

5 participants