Skip to content

Commit 9ac07d2

Browse files
authored
fix: RenameIndex should drop old index (go-gorm#151)
1 parent cb7f946 commit 9ac07d2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

migrator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
322322
var sql string
323323
m.DB.Raw("SELECT sql FROM sqlite_master WHERE type = ? AND tbl_name = ? AND name = ?", "index", stmt.Table, oldName).Row().Scan(&sql)
324324
if sql != "" {
325+
if err := m.DropIndex(value, oldName); err != nil {
326+
return err
327+
}
325328
return m.DB.Exec(strings.Replace(sql, oldName, newName, 1)).Error
326329
}
327330
return fmt.Errorf("failed to find index with name %v", oldName)

0 commit comments

Comments
 (0)