From 5b41d53f255dfca0af661e251e3ddcc16e08eb8b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 8 Feb 2024 16:26:18 +0800 Subject: [PATCH] Fix bug --- migrate/migrate.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/migrate/migrate.go b/migrate/migrate.go index 1085a7d0..cd553ecb 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "reflect" "xorm.io/xorm" "xorm.io/xorm/schemas" @@ -196,19 +197,13 @@ func (m *Migrate) createMigrationTableIfNotExists() error { return nil } - idCol := schemas.Column{ - Name: m.options.IDColumnName, - SQLType: schemas.SQLType{ - Name: "VARCHAR", - DefaultLength: 255, - }, - IsPrimaryKey: true, - } + idCol := schemas.NewColumn(m.options.IDColumnName, "", schemas.SQLType{ + Name: "VARCHAR", + }, 255, 0, true) + idCol.IsPrimaryKey = true - table := &schemas.Table{ - Name: m.options.TableName, - } - table.AddColumn(&idCol) + table := schemas.NewTable(m.options.TableName, reflect.TypeOf(new(schemas.Table))) + table.AddColumn(idCol) sql, _, err := m.db.Dialect().CreateTableSQL(context.Background(), m.db.DB(), table, m.options.TableName) if err != nil {