No, it means that you did not specify the whatisness of grandParent, parent, or 
child; and/or, you have not enabled foreign_keys.

https://sqlite.org/lang_createtable.html
https://sqlite.org/pragma.html#pragma_foreign_keys

NB:  I have compiled the CLI with foreign key enforcement ON be default.  The 
default distributions usually have foreign keys enforcement turned off, 
because, well, who wants a database that enforces referential integrity?  (All 
kidding aside, the reason that foreign key enforcement is OFF by default is to 
maintain backward compatibility with older versions of SQLite that "parsed" 
such constraints but did not allow for enforcement of them).

SQLite version 3.26.0 2018-10-23 13:48:19
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table grandParent (id PRIMARY KEY );
sqlite> create table parent (id PRIMARY KEY REFERENCES grandParent(id));
sqlite> create table child (id PRIMARY KEY REFERENCES parent(id));
sqlite> insert into parent values (1);
Error: FOREIGN KEY constraint failed
sqlite> insert into child values (1);
Error: FOREIGN KEY constraint failed
sqlite> insert into grandparent values (1);
sqlite> insert into parent values (1);
sqlite> insert into child values (1);
sqlite> delete from parent where id=1;
Error: FOREIGN KEY constraint failed
sqlite> delete from grandparent where id=1;
Error: FOREIGN KEY constraint failed
sqlite> delete from child where id=1;
sqlite> delete from grandparent where id=1;
Error: FOREIGN KEY constraint failed
sqlite> delete from parent where id=1;
sqlite> delete from grandparent where id=1;
sqlite>

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Roman Fleysher
>Sent: Wednesday, 24 October, 2018 22:30
>To: General Discussion of SQLite Database
>Subject: [sqlite] nested foreign keys
>
>Dear SQLiters,
>
>I am trying to set up what I would call "nested foreign keys":
>
>create grandParent (id PRIMARY KEY )
>create parent (id PRIMARY KEY REFERENCES grandParent(id))
>create child (id PRIMARY KEY REFERENCES parent(id))
>
>SQLite complains. Does it mean that grand children are not allowed?
>
>Thank you,
>
>Roman
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to