From 8edea305f6733c424862f75cf29a550e21c9b02a Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Sun, 16 Nov 2025 08:35:09 +0530 Subject: [PATCH 1/2] allow null for unique columns --- core/translate/insert.rs | 2 +- testing/null.test | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/translate/insert.rs b/core/translate/insert.rs index 234323cd7..4f13f2b2f 100644 --- a/core/translate/insert.rs +++ b/core/translate/insert.rs @@ -1648,7 +1648,7 @@ fn translate_column( } else if let Some(default_expr) = column.default.as_ref() { translate_expr(program, None, default_expr, column_register, resolver)?; } else { - let nullable = !column.notnull() && !column.primary_key() && !column.unique(); + let nullable = !column.notnull() && !column.primary_key(); if !nullable { crate::bail_parse_error!( "column {} is not nullable", diff --git a/testing/null.test b/testing/null.test index 682c23bfa..814ce6dbd 100755 --- a/testing/null.test +++ b/testing/null.test @@ -26,3 +26,9 @@ do_execsql_test sel-true { do_execsql_test sel-false { select false; } {0} + +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); + select * from t; +} {1|} \ No newline at end of file From 3de37d3f646f3c8f1522d33c0a8be2ab17f42144 Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Sun, 16 Nov 2025 08:54:15 +0530 Subject: [PATCH 2/2] 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);