SQLite In-memory Cascade Delete not working in tests #4883
-
BackendSQLite Diesel version2.3.2 Diesel Features"sqlite", "returning_clauses_for_sqlite_3_35", "time", "chrono" Operating System VersionArch Linux Third party librariesdiesel_migrations = "2.3.0", time="0.3.44" What do you want to do?A In unit tests with an in-memory database (via ":memory:"), deleting the User then looking up the UserStats table returns an Compile time errorNo response What code do you already have?#[test]
fn remove_user_should_also_remove_stats()
{
let mut db = load_migrations();
write_user_stats_with_db(&mut db);
let delete_res = diesel::delete(
users::table.filter(users::id.eq(0))
)
.execute(&mut db);
assert!(delete_res.is_ok());
// Check the UserStats are also deleted
let found_stats = userstats::table
.find(1)
.first::<UserStats>(&mut db)
.optional();
assert!(found_stats.unwrap().is_none()); // <---- failing
}== SQLITE MIGRATIONS == |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Given that you can reproduce the same behaviour by using the sqlite3 binary and execute the same queries there manually, this is expected behaviour from diesels side. We don't hide any database specific behaviour like that. Now you can change the default SQLite behaviour by tweaking SQLite settings like |
Beta Was this translation helpful? Give feedback.
Given that you can reproduce the same behaviour by using the sqlite3 binary and execute the same queries there manually, this is expected behaviour from diesels side. We don't hide any database specific behaviour like that.
Now you can change the default SQLite behaviour by tweaking SQLite settings like
PRAGMA foreign_keysto make SQLite behave more like you expect.