mirror of https://github.com/go-gorm/gorm.git
Respect ignore migration when add column (#4276)
continue https://github.com/go-gorm/gorm/pull/4028
This commit is contained in:
parent
d278ca49ef
commit
d7911300f8
|
@ -295,10 +295,13 @@ func (m Migrator) RenameTable(oldName, newName interface{}) error {
|
||||||
func (m Migrator) AddColumn(value interface{}, field string) error {
|
func (m Migrator) AddColumn(value interface{}, field string) error {
|
||||||
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
||||||
if field := stmt.Schema.LookUpField(field); field != nil {
|
if field := stmt.Schema.LookUpField(field); field != nil {
|
||||||
return m.DB.Exec(
|
if !field.IgnoreMigration {
|
||||||
"ALTER TABLE ? ADD ? ?",
|
return m.DB.Exec(
|
||||||
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, m.DB.Migrator().FullDataTypeOf(field),
|
"ALTER TABLE ? ADD ? ?",
|
||||||
).Error
|
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, m.DB.Migrator().FullDataTypeOf(field),
|
||||||
|
).Error
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to look up field with name: %s", field)
|
return fmt.Errorf("failed to look up field with name: %s", field)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue