From 9e5a4e30b4045ea663b8c03a57ddefd9673f2356 Mon Sep 17 00:00:00 2001 From: heige Date: Tue, 3 Aug 2021 11:40:57 +0800 Subject: [PATCH] Fix migrator GuessConstraintAndTable method for return value for *schema.Check (#4527) --- migrator/migrator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 80d58efd..012ccf65 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -503,9 +503,10 @@ func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (_ } if field := stmt.Schema.LookUpField(name); field != nil { - for _, cc := range checkConstraints { - if cc.Field == field { - return nil, &cc, stmt.Table + for k := range checkConstraints { + if checkConstraints[k].Field == field { + v := checkConstraints[k] + return nil, &v, stmt.Table } }