diff --git a/dialects/mysql.go b/dialects/mysql.go index 5663d1dd..82505707 100644 --- a/dialects/mysql.go +++ b/dialects/mysql.go @@ -397,6 +397,9 @@ func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string { // ModifyColumnSQL returns a SQL to modify SQL func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string { s, _ := ColumnString(db.dialect, col, false, true) + if col.Comment != "" { + s += fmt.Sprintf(" COMMENT '%s'", col.Comment) + } return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s) } diff --git a/integrations/engine_test.go b/integrations/engine_test.go index d0b293bf..86ed7344 100644 --- a/integrations/engine_test.go +++ b/integrations/engine_test.go @@ -311,7 +311,7 @@ func TestColumnCommentUpdate(t *testing.T) { assert.NoError(t, testEngine.Sync2(new(TestCommentUpdate2))) // modify table column comment switch testEngine.Dialect().URI().DBType { - case schemas.POSTGRES: // only postgres dialect implement the feature of modify comment in postgres.ModifyColumnSQL + case schemas.POSTGRES, schemas.MYSQL: // only postgres / mysql dialect implement the feature of modify comment in postgres.ModifyColumnSQL default: t.Skip() return diff --git a/sync.go b/sync.go index 3d9c30f2..11e75404 100644 --- a/sync.go +++ b/sync.go @@ -181,8 +181,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) } } } else if col.Comment != oriCol.Comment { - // only postgres dialect implement update comment now. - if engine.dialect.URI().DBType == schemas.POSTGRES { + if engine.dialect.URI().DBType == schemas.POSTGRES || + engine.dialect.URI().DBType == schemas.MYSQL { _, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col)) } }