@@ -225,6 +225,29 @@ func TestOra03146TTC(t *testing.T) {
225
225
t .Log ("执行成功,影响行数:" , result .RowsAffected )
226
226
}
227
227
228
+ type testNoDefaultDBValues struct {
229
+ UID string `gorm:"column:uid;type:varchar(50);comment:用户身份标识" json:"uid"`
230
+ Name string `gorm:"column:name;size:50;comment:用户姓名" json:"name"`
231
+
232
+ Account string `gorm:"column:account;type:varchar(50);comment:登录账号" json:"account"`
233
+ Password string `gorm:"column:password;type:varchar(512);comment:登录密码(密文)" json:"password"`
234
+
235
+ Email string `gorm:"column:email;type:varchar(128);comment:邮箱地址" json:"email"`
236
+ PhoneNumber string `gorm:"column:phone_number;type:varchar(15);comment:E.164" json:"phoneNumber"`
237
+
238
+ Sex string `gorm:"column:sex;type:char(1);comment:性别" json:"sex"`
239
+ Birthday * time.Time `gorm:"column:birthday;->:false;<-:create;comment:生日" json:"birthday,omitempty"`
240
+
241
+ UserType int `gorm:"column:user_type;size:8;comment:用户类型" json:"userType"`
242
+
243
+ Enabled bool `gorm:"column:enabled;comment:是否可用" json:"enabled"`
244
+ Remark string `gorm:"column:remark;size:1024;comment:备注信息" json:"remark"`
245
+ }
246
+
247
+ func (testNoDefaultDBValues ) TableName () string {
248
+ return "test_no_default_db_values"
249
+ }
250
+
228
251
func TestCreateInBatches (t * testing.T ) {
229
252
db , err := dbNamingCase , dbErrors [0 ]
230
253
if err != nil {
@@ -235,8 +258,8 @@ func TestCreateInBatches(t *testing.T) {
235
258
return
236
259
}
237
260
238
- model := TestTableUser {}
239
- migrator := db .Set ("gorm:table_comments" , "用户信息表 " ).Migrator ()
261
+ model := testNoDefaultDBValues {}
262
+ migrator := db .Set ("gorm:table_comments" , "没有由数据库分配的默认值字段测试表 " ).Migrator ()
240
263
if migrator .HasTable (model ) {
241
264
if err = migrator .DropTable (model ); err != nil {
242
265
t .Fatalf ("DropTable() error = %v" , err )
@@ -248,7 +271,7 @@ func TestCreateInBatches(t *testing.T) {
248
271
t .Log ("AutoMigrate() success!" )
249
272
}
250
273
251
- data := []TestTableUser {
274
+ data := []testNoDefaultDBValues {
252
275
{UID : "U1" , Name : "Lisa" , Account : "lisa" , Password : "H6aLDNr" , PhoneNumber : "+8616666666666" , Sex : "0" , UserType : 1 , Enabled : true },
253
276
{UID : "U2" , Name : "Daniela" , Account : "daniela" , Password : "Si7l1sRIC79" , PhoneNumber : "+8619999999999" , Sex : "1" , UserType : 1 , Enabled : true },
254
277
{UID : "U3" , Name : "Tom" , Account : "tom" , Password : "********" , PhoneNumber : "+8618888888888" , Sex : "1" , UserType : 1 , Enabled : true },
0 commit comments