Home > Back-end >  SQLITE foreign key constraint violated without error
SQLITE foreign key constraint violated without error

Time:11-25

I was able to execute the following:

SQLite version 2.8.17
Enter ".help" for instructions
sqlite> create table a (aid integer primary key, name text);
sqlite> create table b (bid integer, aid integer, name text, foreign key(aid) references a(aid));
sqlite> insert into b values (1,1,'wtf');
sqlite> select * from b;
1|1|wtf
sqlite> select * from a;
sqlite>

It seems to me that the insertion should fail, since there is not an id value of '1' (or any ids, really) in table a.

Am I fundamentally misunderstanding foreign keys, sqlite, or both?

CodePudding user response:

SQLite Version 2.8.17 (2005-12-19) doesn't support Foreign keys. Foreign key support was not introduced until 3.6.19.

  • Related