What do your inserts look like?  This SQL will function as expected:

    CREATE TABLE grandparent (id INTEGER PRIMARY KEY);
    CREATE TABLE parent (id INTEGER PRIMARY KEY REFERENCES grandparent(id));
    CREATE TABLE child (id INTEGER PRIMARY KEY REFERENCES parent(id));

    INSERT INTO grandparent VALUES (1);
    INSERT INTO parent VALUES (1);
    INSERT INTO child VALUES (1);

You can mix up the insertion order if you defer checking (
https://www.sqlite.org/foreignkeys.html#fk_deferred); if not, you'll have
to insert parents before children.

- David

On Wed, Oct 24, 2018 at 11:44 PM Roman Fleysher <
roman.fleys...@einstein.yu.edu> wrote:

> The statements work. Insertion fails.
>
> Roman
>
> ________________________________________
> From: sqlite-users [sqlite-users-boun...@mailinglists.sqlite.org] on
> behalf of David Yip [dw...@peach-bun.com]
> Sent: Thursday, October 25, 2018 12:37 AM
> To: SQLite mailing list
> Subject: Re: [sqlite] nested foreign keys
>
> These statements worked for me:
>
>
> CREATE TABLE grandparent (id INTEGER PRIMARY KEY);
>
> CREATE TABLE parent (id INTEGER PRIMARY KEY REFERENCES grandparent(id));
>
> CREATE TABLE child (id INTEGER PRIMARY KEY REFERENCES parent(id));
>
>
> The foreign key constraints work as you'd expect also.
>
>
> What are you doing and what error are you seeing?
>
>
> - David
>
> On Wed, Oct 24, 2018 at 11:30 PM Roman Fleysher <
> roman.fleys...@einstein.yu.edu> wrote:
>
> > 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
> _______________________________________________
> 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