From 0273856e4d9744c98aa42b98d485d726099e9020 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 31 Aug 2020 16:27:22 +0800 Subject: [PATCH] Don't alter column with full column data type, close #3339 --- migrator/migrator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index d93b8a6d..c736a3e0 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -297,10 +297,12 @@ func (m Migrator) DropColumn(value interface{}, name string) error { func (m Migrator) AlterColumn(value interface{}, field string) error { return m.RunWithValue(value, func(stmt *gorm.Statement) error { if field := stmt.Schema.LookUpField(field); field != nil { + fileType := clause.Expr{SQL: m.DataTypeOf(field)} return m.DB.Exec( "ALTER TABLE ? ALTER COLUMN ? TYPE ?", - clause.Table{Name: stmt.Table}, clause.Column{Name: field.DBName}, m.DB.Migrator().FullDataTypeOf(field), + clause.Table{Name: stmt.Table}, clause.Column{Name: field.DBName}, fileType, ).Error + } return fmt.Errorf("failed to look up field with name: %s", field) })