diff --git a/migrator/migrator.go b/migrator/migrator.go index c455a294..9493a00c 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -32,6 +32,7 @@ func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error stmt := &gorm.Statement{DB: m.DB} if m.DB.Statement != nil { stmt.Table = m.DB.Statement.Table + stmt.TableExpr = m.DB.Statement.TableExpr } if table, ok := value.(string); ok { @@ -161,6 +162,10 @@ func (m Migrator) CreateTable(values ...interface{}) error { hasPrimaryKeyInDataType bool ) + if stmt.TableExpr != nil { + values[0] = *stmt.TableExpr + } + for _, dbName := range stmt.Schema.DBNames { field := stmt.Schema.FieldsByDBName[dbName] createTableSQL += "? ?"