> I get a foreign Key mismatch error.  No matter what value I supply for
> FKeyColumn, even NULL, I get the same error.

Did you create unique index on t1 (RefColumn) ? IIRC, SQLite always
fails foreign key check if there's no index on a referenced column.


Pavel


On Sun, Apr 1, 2012 at 8:22 PM, Pete <p...@mollysrevenge.com> wrote:
> I'm running into an issue with foreign keys where no matter what value I
> supply for a child key, I get a foreign key mismatch error.  Here are my
> test tables.
>
> CREATE TABLE "t1" ("RefColumn" TEXT ,"Data" TEXT )
>
> CREATE TABLE "t2" ("FKeyColumn" TEXT  REFERENCES "t1"("RefColumn"),"Data"
> TEXT )
>
>
> PRAGMA foreign_keys is set to 1.
>
>
> Put a couple of entries into t1:
>
>
> SELECT * FROM t1
>
>
> RefColumn   Data
>
> ----------  ----------
>
> a                   aaa
>
> b                   bbb
>
>
> Now insert a row into t2
>
> INSERT INTO t2 VALUES ('a','aaa');
>
> I get a foreign Key mismatch error.  No matter what value I supply for
> FKeyColumn, even NULL, I get the same error.
>
> I disabled foreign keys, then the INSERT worked.  Enabled foreign keys
> again, it fails again.
>
> And even more concerning "DELETE FROM t2" also produces a foreign key
> mismatch error.
>
> What am I doing wrong?
>
>
> --
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to