Fix auto migration always alert table, close #4198
This commit is contained in:
		
							parent
							
								
									d8a710cba2
								
							
						
					
					
						commit
						3a3b82263a
					
				| @ -390,7 +390,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy | |||||||
| 	alterColumn := false | 	alterColumn := false | ||||||
| 
 | 
 | ||||||
| 	// check size
 | 	// check size
 | ||||||
| 	if length, _ := columnType.Length(); length != int64(field.Size) { | 	if length, ok := columnType.Length(); length != int64(field.Size) { | ||||||
| 		if length > 0 && field.Size > 0 { | 		if length > 0 && field.Size > 0 { | ||||||
| 			alterColumn = true | 			alterColumn = true | ||||||
| 		} else { | 		} else { | ||||||
| @ -399,7 +399,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy | |||||||
| 			matches := regRealDataType.FindAllStringSubmatch(realDataType, -1) | 			matches := regRealDataType.FindAllStringSubmatch(realDataType, -1) | ||||||
| 			matches2 := regFullDataType.FindAllStringSubmatch(fullDataType, -1) | 			matches2 := regFullDataType.FindAllStringSubmatch(fullDataType, -1) | ||||||
| 			if (len(matches) == 1 && matches[0][1] != fmt.Sprint(field.Size) || !field.PrimaryKey) && | 			if (len(matches) == 1 && matches[0][1] != fmt.Sprint(field.Size) || !field.PrimaryKey) && | ||||||
| 				(len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length)) { | 				(len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length) && ok) { | ||||||
| 				alterColumn = true | 				alterColumn = true | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -90,7 +90,7 @@ func TestAutoMigrateSelfReferential(t *testing.T) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestSmartMigrateColumn(t *testing.T) { | func TestSmartMigrateColumn(t *testing.T) { | ||||||
| 	fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] | 	fullSupported := map[string]bool{"mysql": true}[DB.Dialector.Name()] | ||||||
| 
 | 
 | ||||||
| 	type UserMigrateColumn struct { | 	type UserMigrateColumn struct { | ||||||
| 		ID       uint | 		ID       uint | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu