GORM Playground Link

No time to make it for now.

Description

unique Field (having uniqueIndex or index:,unique tag) always causes migration.

The reason is this line:

https://github.com/go-gorm/gorm/blob/7da24d1d52be944fe5058792f8bdcf9572b48a1f/schema/field.go#L116

field.Unique is only true when tagSettings["UNIQUE"] is true.

But uniqueIndex tag only sets tagSettings["UNIQUEINDEX"] and index tag only sets tagSettings["INDEX"].

And field migration is checking field.Unique in this line:

https://github.com/go-gorm/gorm/blob/7da24d1d52be944fe5058792f8bdcf9572b48a1f/migrator/migrator.go#L481

Therefore field migration will always be performed.

Maybe schema/field.go#L116 should be changed to

field := &Field{
    ...,
    Unique: false,
}
if indexes, err := parseFieldIndexes(field); err == nil {
    for _, index := range indexes {
        if index.Class == "UNIQUE" {
            field.Unique = true
            break
        }
    }
}

But I don't think this treatment is good. Does field.Unique deserve to exist?

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: Nomango

Seems like #5942 is the same issue.

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: jinzhu

Should be fixed in commit https://github.com/go-gorm/gorm/commit/3d91802b1d1bd5ad175ac43fac062fd9f8de98be