From 021d7b33143de37b743d1cf660974e9c8d3f80ea Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 17 Mar 2016 18:12:21 +0800 Subject: [PATCH] Fix migrate indexes with CreateTable, AutoMigrate for soft delete --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 56c80019..cd445555 100644 --- a/main.go +++ b/main.go @@ -466,7 +466,7 @@ func (s *DB) RecordNotFound() bool { // CreateTable create table for models func (s *DB) CreateTable(models ...interface{}) *DB { - db := s.clone() + db := s.Unscoped() for _, model := range models { db = db.NewScope(model).createTable().db } @@ -517,7 +517,7 @@ func (s *DB) HasTable(value interface{}) bool { // AutoMigrate run auto migration for given models, will only add missing fields, won't delete/change current data func (s *DB) AutoMigrate(values ...interface{}) *DB { - db := s.clone() + db := s.Unscoped() for _, value := range values { db = db.NewScope(value).autoMigrate().db } @@ -547,7 +547,7 @@ func (s *DB) AddIndex(indexName string, columns ...string) *DB { // AddUniqueIndex add unique index for columns with given name func (s *DB) AddUniqueIndex(indexName string, columns ...string) *DB { - scope := s.clone().Unscoped().NewScope(s.Value) + scope := s.Unscoped().NewScope(s.Value) scope.addIndex(true, indexName, columns...) return scope.db }