         if SwiftData.EnableWAL {
             let cursor = executeQueryUnsafe("PRAGMA journal_mode=WAL", factory: StringFactory)
             assert(cursor[0] as! String == "wal", "WAL journal mode set")
+        }
+
+        if SwiftData.EnableForeignKeys {
+            let cursor = executeQueryUnsafe("PRAGMA foreign_keys=ON", factory: IntFactory)
         }
 
         // Retry queries before returning locked errors.

        statement = nil
        super.close()
    }
}
public class SwiftData {
    let filename: String

    static var EnableWAL = true
    static var EnableForeignKeys = true

    /// Used for testing.
    static var ReuseConnections = true
