diff --git a/migrator/migrator.go b/migrator/migrator.go index b15a43ef..667d496e 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -35,6 +35,7 @@ type Migrator struct { // Config schema config type Config struct { CreateIndexAfterCreateTable bool + CreateTableUseIfNotExists bool DB *gorm.DB gorm.Dialector } @@ -213,6 +214,10 @@ func (m Migrator) CreateTable(values ...interface{}) error { hasPrimaryKeyInDataType bool ) + if m.CreateTableUseIfNotExists { + createTableSQL = "CREATE TABLE IF NOT EXISTS ? (" + } + for _, dbName := range stmt.Schema.DBNames { field := stmt.Schema.FieldsByDBName[dbName] if !field.IgnoreMigration {