From d7911300f83d79a57bc456a487addc031f2d9ff5 Mon Sep 17 00:00:00 2001 From: yrong1997 Date: Tue, 13 Apr 2021 09:39:43 +0800 Subject: [PATCH] Respect ignore migration when add column (#4276) continue https://github.com/go-gorm/gorm/pull/4028 --- migrator/migrator.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 075b5ca6..1800ab54 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -295,10 +295,13 @@ func (m Migrator) RenameTable(oldName, newName interface{}) error { func (m Migrator) AddColumn(value interface{}, field string) error { return m.RunWithValue(value, func(stmt *gorm.Statement) error { if field := stmt.Schema.LookUpField(field); field != nil { - return m.DB.Exec( - "ALTER TABLE ? ADD ? ?", - m.CurrentTable(stmt), clause.Column{Name: field.DBName}, m.DB.Migrator().FullDataTypeOf(field), - ).Error + if !field.IgnoreMigration { + return m.DB.Exec( + "ALTER TABLE ? ADD ? ?", + 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) })