From f8bd4c4875a269b97a2175a0c719805692d0d210 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 24 Jan 2021 10:23:04 +0800 Subject: [PATCH] Don't create index if there are error exist, close #3976 --- migrator/migrator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index e25d427c..e8718d18 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -183,7 +183,9 @@ func (m Migrator) CreateTable(values ...interface{}) error { for _, idx := range stmt.Schema.ParseIndexes() { if m.CreateIndexAfterCreateTable { defer func(value interface{}, name string) { - errr = tx.Migrator().CreateIndex(value, name) + if errr == nil { + errr = tx.Migrator().CreateIndex(value, name) + } }(value, idx.Name) } else { if idx.Class != "" {