Skip to content

Commit 008f72f

Browse files
committed
tests:sqilte: enable FOREIGN_KEYS inside OpenTestConnection instead of init
1 parent 6bef318 commit 008f72f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tests/tests_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ func init() {
4343
}
4444

4545
RunMigrations()
46-
if DB.Dialector.Name() == "sqlite" {
47-
DB.Exec("PRAGMA foreign_keys = ON")
48-
}
4946
}
5047
}
5148

@@ -89,7 +86,9 @@ func OpenTestConnection(cfg *gorm.Config) (db *gorm.DB, err error) {
8986
db, err = gorm.Open(mysql.Open(dbDSN), cfg)
9087
default:
9188
log.Println("testing sqlite3...")
92-
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db?_foreign_keys=on")), cfg)
89+
if db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), cfg); err == nil {
90+
err = db.Exec("PRAGMA foreign_keys = ON").Error
91+
}
9392
}
9493

9594
if err != nil {

0 commit comments

Comments
 (0)