Skip to content

Commit de49b09

Browse files
committed
tests/sqilte: enable FOREIGN_KEYS inside OpenTestConnection
1 parent 6bef318 commit de49b09

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/tests_test.go

Lines changed: 4 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,10 @@ 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+
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), cfg)
90+
if err == nil {
91+
db.Exec("PRAGMA foreign_keys = ON")
92+
}
9393
}
9494

9595
if err != nil {

0 commit comments

Comments
 (0)