On Sun, 06 Dec 2009 00:05:28 -0700, Paul Shaffer
<sqli...@cyberplasm.com> wrote:

>I found where I was getting a 'foreign key mismatch' error, but I don't
>know why. There are 2 versions of the last table below. They look like they
>are about the same to me, but one causes the error. The error occurs when I
>am doing a cascading delete in unrelated tables, and the problem table has
>no rows. It's important for me since it impacts the code for a tool I am
>writing. Thanks in advance for any help.

Your code is not valid.
This may not be the cause of the error, but anyway.

>-- causes foreign key mismatch error:
>
>CREATE TABLE [P_Item_2] (
>    [ItemID] integer NOT NULL,
>    [ColumnID] integer NOT NULL,
>    [ParentID] integer NOT NULL,
>    PRIMARY KEY ([ItemID], [ColumnID]),
>    FOREIGN KEY([ColumnID])
>        REFERENCES [P_item] ([ColumnID]) ON UPDATE CASCADE ON DELETE
>    FOREIGN KEY([ParentID])
>        REFERENCES [P_item] ([ItemID]) ON UPDATE CASCADE ON DELETE CASCADE,
>CASCADE
>)


Shouldn't that be:

CREATE TABLE [P_Item_2] (
    [ItemID] integer NOT NULL,
    [ColumnID] integer NOT NULL,
    [ParentID] integer NOT NULL,
    PRIMARY KEY ([ItemID], [ColumnID]),
    FOREIGN KEY([ColumnID])
                REFERENCES [P_item] ([ColumnID]) 
                ON UPDATE CASCADE 
                ON DELETE CASCADE
    FOREIGN KEY([ParentID])
                REFERENCES [P_item] ([ItemID])
                ON UPDATE CASCADE 
                ON DELETE CASCADE
);

-- 
  (  Kees Nuyt
  )
c[_]
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to