diff --git a/orm/models_info_f.go b/orm/models_info_f.go index b5cbd958..33506829 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -206,8 +206,8 @@ checkType: if err != nil { goto end } - if fieldType == TypeTextField && size != "" { - fieldType = TypeCharField + if fieldType == TypeCharField && tags["type"] == "text" { + fieldType = TypeTextField } if fieldType == TypeFloatField && (digits != "" || decimals != "") { fieldType = TypeDecimalField @@ -312,7 +312,7 @@ checkType: fi.size = int(v) } } else { - err = fmt.Errorf("size must be specify") + fi.size = 255 } case TypeTextField: fi.index = false diff --git a/orm/models_test.go b/orm/models_test.go index bd2dcd28..c9bbce2b 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -15,7 +15,7 @@ import ( type Data struct { Id int Boolean bool - Char string `orm:size(50)` + Char string `orm:"size(50)"` Text string `orm:"type(text)"` Date time.Time `orm:"type(date)"` DateTime time.Time @@ -100,7 +100,7 @@ type Post struct { Id int User *User `orm:"rel(fk)"` Title string `orm:"size(60)"` - Content string `` + Content string `orm:"type(text)"` Created time.Time `orm:"auto_now_add"` Updated time.Time `orm:"auto_now"` Tags []*Tag `orm:"rel(m2m)"` @@ -125,7 +125,7 @@ func NewTag() *Tag { type Comment struct { Id int Post *Post `orm:"rel(fk)"` - Content string `` + Content string `orm:"type(text)"` Parent *Comment `orm:"null;rel(fk)"` Created time.Time `orm:"auto_now_add"` } diff --git a/orm/models_utils.go b/orm/models_utils.go index 1efaad97..fe9cb965 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -64,7 +64,7 @@ func getFieldType(val reflect.Value) (ft int, err error) { case reflect.Bool: ft = TypeBooleanField case reflect.String: - ft = TypeTextField + ft = TypeCharField case reflect.Invalid: default: if elm.CanInterface() {