-------- Original Message -------- > On Dec 4, 2009, at 12:31 PM, Paul Shaffer wrote: > >> Below are 3 tables. When I delete a row in Item with related rows in >> Item_attribute I get the dreaded "foreign key mismatch" error. I've >> read >> through the documentation and don't see what I'm doing wrong. > > There are no FK mismatches in the three table definitions here. > > Maybe the problem is in a different part of the schema. Any other FK > constraints reference table [Item]? Any ON DELETE triggers on table > [Item]? > > There are no triggers in the database.
Other tables have FK constraints to Item(ItemID), and I see what you mean. One of the other tables is probably causing the problem. I deleted the table below from the database, and cascading deletes are working without error. I don't see a problem with this table either. CREATE TABLE [T1] ( "ItemID" integer NOT NULL, "AttributeID" integer NOT NULL, "UniqueID" guid NOT NULL, PRIMARY KEY ([ItemID], [AttributeID]) , FOREIGN KEY ([AttributeID]) REFERENCES [T2]([AttributeID]) ON DELETE CASCADE, FOREIGN KEY ([ItemID]) REFERENCES [Item]([ItemID]) ON DELETE CASCADE ) Here is [T2], it's not the same as table as [Attribute] below. CREATE TABLE [T2] ( "AttributeID" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "Name" nvarchar(255) NOT NULL COLLATE NOCASE DEFAULT '', ) >> sqlite v 1.6.20 >> >> CREATE TABLE [Item_attribute] ( >> "ItemID" integer NOT NULL, >> "AttributeID" integer NOT NULL, >> PRIMARY KEY ([ItemID], [AttributeID]) >> , >> FOREIGN KEY ([AttributeID]) >> REFERENCES [Attribute]([AttributeID]) ON DELETE CASCADE, >> FOREIGN KEY ([ItemID]) >> REFERENCES [Item]([ItemID]) ON DELETE CASCADE >> ) >> >> >> CREATE TABLE [Item] ( >> "ItemID" integer PRIMARY KEY AUTOINCREMENT NOT NULL, >> "ItemName" varchar(255) NOT NULL COLLATE NOCASE DEFAULT '' >> ) >> >> CREATE TABLE [Attribute] ( >> "AttributeID" integer PRIMARY KEY AUTOINCREMENT NOT NULL, >> "Name" varchar(255) NOT NULL COLLATE NOCASE DEFAULT '' >> >> ) >> >> >> >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users