Don't alter column with full column data type, close #3339

This commit is contained in:
Jinzhu 2020-08-31 16:27:22 +08:00
parent 496db1f13e
commit 0273856e4d
1 changed files with 3 additions and 1 deletions

View File

@ -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)
})