From 3de37d3f646f3c8f1522d33c0a8be2ab17f42144 Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Sun, 16 Nov 2025 08:54:15 +0530 Subject: [PATCH] dont validate fkey on parent add tests correct msitake and add null test issue add fkey test --- core/schema.rs | 2 -- testing/foreign_keys.test | 31 +++++++++++++++++++++++++++++++ testing/null.test | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/schema.rs b/core/schema.rs index 4990b4b3c..75ef830f5 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -968,8 +968,6 @@ impl Schema { None } else { find_parent_unique(&parent_cols) - .ok_or_else(|| fk_mismatch_err(&child.name, &parent_tbl.name))? - .into() }; fk.validate()?; out.push(ResolvedFkRef { diff --git a/testing/foreign_keys.test b/testing/foreign_keys.test index 360ccbc8f..b28497167 100755 --- a/testing/foreign_keys.test +++ b/testing/foreign_keys.test @@ -1207,3 +1207,34 @@ do_execsql_test_in_memory_any_error fk-update-parent-multi-col-pk-2 { INSERT INTO child VALUES(1, 2); UPDATE parent SET b = 3 WHERE a = 1 AND b = 2; } + +# https://github.com/tursodatabase/turso/issues/3965 +do_execsql_test_on_specific_db {:memory:} fk-no-val-on-parent { + PRAGMA foreign_keys=ON; + CREATE TABLE t1( + a INT, + b INT + ); + CREATE TABLE t2( + x INT, + y INT, + FOREIGN KEY (x, y) REFERENCES t1(a, b) + ); + INSERT INTO t1(a, b) VALUES (5, 10); + SELECT * FROM t1; + } {5|10} + + do_execsql_test_in_memory_any_error fk-val-on-parent { + PRAGMA foreign_keys=ON; + CREATE TABLE t1( + a INT, + b INT + ); + CREATE TABLE t2( + x INT, + y INT, + FOREIGN KEY (x, y) REFERENCES t1(a, b) + ); + INSERT INTO t2(a, b) VALUES (5, 10); + SELECT * FROM t2; + } \ No newline at end of file diff --git a/testing/null.test b/testing/null.test index 814ce6dbd..6b4d5c142 100755 --- a/testing/null.test +++ b/testing/null.test @@ -27,6 +27,7 @@ do_execsql_test sel-false { select false; } {0} +# https://github.com/tursodatabase/turso/issues/3966 do_execsql_test_on_specific_db {:memory:} not-null-just-cuz-unique { create table t (a int, x int unique); insert into t(a) values(1);