diff --git a/session_schema.go b/session_schema.go index 7ca89f26..5e576c29 100644 --- a/session_schema.go +++ b/session_schema.go @@ -344,9 +344,15 @@ func (session *Session) Sync2(beans ...interface{}) error { } } } + if col.Default != oriCol.Default { - engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s", - tbName, col.Name, oriCol.Default, col.Default) + if (col.SQLType.Name == core.Bool || col.SQLType.Name == core.Boolean) && + ((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") || + (strings.EqualFold(col.Default, "false") && oriCol.Default == "0")) { + } else { + engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s", + tbName, col.Name, oriCol.Default, col.Default) + } } if col.Nullable != oriCol.Nullable { engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v", diff --git a/session_schema_test.go b/session_schema_test.go index 0badc338..4505381f 100644 --- a/session_schema_test.go +++ b/session_schema_test.go @@ -332,3 +332,16 @@ func TestSync2_2(t *testing.T) { assert.True(t, tableNames[table.Name]) } } + +func TestSync2_Default(t *testing.T) { + type TestSync2Default struct { + Id int64 + UserId int64 `xorm:"default(1)"` + IsMember bool `xorm:"default(true)"` + Name string `xorm:"default('my_name')"` + } + + assert.NoError(t, prepareEngine()) + assertSync(t, new(TestSync2Default)) + assert.NoError(t, testEngine.Sync2(new(TestSync2Default))) +}