Skip to content

Commit

Permalink
ddl: fix alter column set default wrongly updates the schema (#32249)
Browse files Browse the repository at this point in the history
close #31074
  • Loading branch information
wjhuang2016 authored Feb 11, 2022
1 parent c0244a3 commit 6d2ad99
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4643,10 +4643,11 @@ func (d *ddl) AlterColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt

colName := specNewColumn.Name.Name
// Check whether alter column has existed.
col := table.FindCol(t.Cols(), colName.L)
if col == nil {
oldCol := table.FindCol(t.Cols(), colName.L)
if oldCol == nil {
return ErrBadField.GenWithStackByArgs(colName, ident.Name)
}
col := table.ToColumn(oldCol.Clone())

// Clean the NoDefaultValueFlag value.
col.Flag &= ^mysql.NoDefaultValueFlag
Expand Down

0 comments on commit 6d2ad99

Please sign in to comment.