ddl: fix issue 2293 (#2316)
This commit is contained in:
@ -307,6 +307,7 @@ func (d *ddl) addTableColumn(t table.Table, columnInfo *model.ColumnInfo, reorgI
|
||||
colMeta.defaultVal, _, err = table.GetColDefaultValue(ctx, columnInfo)
|
||||
if err != nil {
|
||||
job.State = model.JobCancelled
|
||||
log.Errorf("[ddl] fatal: this case shouldn't happen, err:%v", err)
|
||||
return errors.Trace(err)
|
||||
}
|
||||
} else if mysql.HasNotNullFlag(columnInfo.Flag) {
|
||||
|
||||
@ -1021,6 +1021,15 @@ func (d *ddl) AddColumn(ctx context.Context, ti ast.Ident, spec *ast.AlterTableS
|
||||
return errors.Trace(err)
|
||||
}
|
||||
|
||||
// Check column default value.
|
||||
colInfo := col.ToInfo()
|
||||
if colInfo.DefaultValue != nil {
|
||||
_, _, err := table.GetColDefaultValue(ctx, colInfo)
|
||||
if err != nil {
|
||||
return errors.Trace(err)
|
||||
}
|
||||
}
|
||||
|
||||
job := &model.Job{
|
||||
SchemaID: schema.ID,
|
||||
TableID: t.Meta().ID,
|
||||
|
||||
@ -505,6 +505,8 @@ func (s *testDBSuite) TestIssue2293(c *C) {
|
||||
s.tk.MustExec("create table t_issue_2293 (a int)")
|
||||
_, err := s.tk.Exec("alter table t add b int not null default ''")
|
||||
c.Assert(err, NotNil)
|
||||
s.tk.MustExec("insert into t_issue_2293 value(1)")
|
||||
s.tk.MustQuery("select * from t_issue_2293").Check(testkit.Rows("1"))
|
||||
}
|
||||
|
||||
func (s *testDBSuite) TestColumn(c *C) {
|
||||
|
||||
Reference in New Issue
Block a user