mirror of https://github.com/go-gorm/gorm.git
Allow create table for other database/schema #3640
This commit is contained in:
parent
db2630cb3a
commit
dd92f8bdc0
|
@ -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 += "? ?"
|
||||
|
|
Loading…
Reference in New Issue