From 22317b43c007f1a4aa21d6bf6c3e5088ce0ca507 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 1 Sep 2020 18:58:16 +0800 Subject: [PATCH] Fix migrate field, failed to migrate when field size changed --- migrator/migrator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index c736a3e0..1aebc50d 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -356,9 +356,9 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy alterColumn = true } else { // has size in data type and not equal - matches := regexp.MustCompile(`[^\d](\d+)[^\d]`).FindAllString(realDataType, 1) + matches := regexp.MustCompile(`[^\d](\d+)[^\d]`).FindAllStringSubmatch(realDataType, -1) matches2 := regexp.MustCompile(`[^\d]*(\d+)[^\d]`).FindAllStringSubmatch(fullDataType, -1) - if len(matches) > 0 && matches[1] != fmt.Sprint(field.Size) || len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length) { + if (len(matches) == 1 && matches[0][1] != fmt.Sprint(field.Size)) && (len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length)) { alterColumn = true } }