From a992c1ea38c4a05a934fb30928a560c3a54190d2 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 12 Apr 2020 13:22:52 +0800 Subject: [PATCH] Fix check has column, index for sqlite --- dialects/sqlite/migrator.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dialects/sqlite/migrator.go b/dialects/sqlite/migrator.go index 4ddcbb5d..601de126 100644 --- a/dialects/sqlite/migrator.go +++ b/dialects/sqlite/migrator.go @@ -30,8 +30,8 @@ func (m Migrator) HasColumn(value interface{}, field string) bool { } return m.DB.Raw( - "SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND (sql LIKE ? OR sql LIKE ? OR sql LIKE ?)", - stmt.Table, `%"`+name+`" %`, `%`+name+` %`, "%`"+name+"`%", + "SELECT count(*) FROM sqlite_master WHERE type = ? AND tbl_name = ? AND (sql LIKE ? OR sql LIKE ? OR sql LIKE ?)", + "table", stmt.Table, `%"`+name+`" %`, `%`+name+` %`, "%`"+name+"`%", ).Row().Scan(&count) }) return count > 0 @@ -41,8 +41,8 @@ func (m Migrator) HasIndex(value interface{}, name string) bool { var count int m.RunWithValue(value, func(stmt *gorm.Statement) error { return m.DB.Raw( - "SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND sql LIKE ?", - stmt.Table, "%INDEX "+name+" ON%", + "SELECT count(*) FROM sqlite_master WHERE type = ? AND tbl_name = ? AND sql LIKE ?", + "index", stmt.Table, "%INDEX "+name+" ON%", ).Row().Scan(&count) }) return count > 0