0

Look, I'm expecting to get an "SQL error: foreign key constraint failed" error, but this never happens, can you guys explain why? Working with sqlite3 db on Android.

sqlite> CREATE TABLE first (id text, value text);
sqlite> CREATE TABLE second (id text, ref text, foreign key(ref) references first(value));
sqlite> INSERT INTO first VALUES("1", "one");
sqlite> INSERT INTO first VALUES("2", "two");
sqlite> INSERT INTO second VALUES("1", "three");

So it is perfectly possible to insert "three", but there is no "three" in the first table. I'm confused.

laalto
  • 144,748
  • 64
  • 275
  • 293
Eugene
  • 57,641
  • 91
  • 219
  • 328
  • possible duplicate of [How do you enforce foreign key constraints in SQLite through Java?](http://stackoverflow.com/questions/9774923/how-do-you-enforce-foreign-key-constraints-in-sqlite-through-java) – Christoff Erasmus Sep 09 '13 at 16:51

1 Answers1

2

Did you make sure FK support is enabled? http://www.sqlite.org/foreignkeys.html#fk_enable

Meldor
  • 236
  • 1
  • 3