ddl: fix issue 2293 (#2316)

This commit is contained in:
Lynn
2016-12-26 10:52:16 +08:00
committed by GitHub
parent 6f95d18e01
commit cd9bd133db
3 changed files with 12 additions and 0 deletions

View File

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

View File

@ -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,

View File

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