diff --git a/pkg/ddl/ddl_api.go b/pkg/ddl/ddl_api.go index 14e048c86c38b..0419493c22231 100644 --- a/pkg/ddl/ddl_api.go +++ b/pkg/ddl/ddl_api.go @@ -6035,8 +6035,8 @@ func (d *ddl) AlterColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt // Clean the NoDefaultValueFlag value. col.DelFlag(mysql.NoDefaultValueFlag) + col.DefaultIsExpr = false if len(specNewColumn.Options) == 0 { - col.DefaultIsExpr = false err = col.SetDefaultValue(nil) if err != nil { return errors.Trace(err) diff --git a/tests/integrationtest/r/ddl/db_integration.result b/tests/integrationtest/r/ddl/db_integration.result index 749c17f08b142..817080ce8e2af 100644 --- a/tests/integrationtest/r/ddl/db_integration.result +++ b/tests/integrationtest/r/ddl/db_integration.result @@ -409,6 +409,13 @@ t CREATE TABLE `t` ( `c` int(10) DEFAULT NULL, `c1` varchar(256) DEFAULT (uuid()) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +create table t (c int(10), c1 varchar(256) default rand()); +alter table t alter column c1 set default 'xx'; +insert into t values (1, default); +select c1 from t; +c1 +xx drop table if exists t1; create table t1 (a int(11) not null auto_increment key, b int(11), c bigint, unique key (a, b, c)); alter table t1 drop index a; diff --git a/tests/integrationtest/t/ddl/db_integration.test b/tests/integrationtest/t/ddl/db_integration.test index 8b5c170681b05..8bd6fe02f9fba 100644 --- a/tests/integrationtest/t/ddl/db_integration.test +++ b/tests/integrationtest/t/ddl/db_integration.test @@ -420,6 +420,13 @@ insert into t(c) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); select count(distinct c1) from t; show create table t; +# TestDefaultValueExpressionWithModifyColumn +drop table if exists t; +create table t (c int(10), c1 varchar(256) default rand()); +alter table t alter column c1 set default 'xx'; +insert into t values (1, default); +select c1 from t; + # TestDropAutoIncrementIndex drop table if exists t1; create table t1 (a int(11) not null auto_increment key, b int(11), c bigint, unique key (a, b, c));