Allow create table for other database/schema #3640

This commit is contained in:
Jinzhu 2020-10-23 11:01:45 +08:00
parent db2630cb3a
commit dd92f8bdc0
1 changed files with 5 additions and 0 deletions

View File

@ -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 += "? ?"