I have SQLite 3 with the following setup (simplified):
create table Location(LocationId integer not null,
LocationCode text not null,
The documentation (hidden in the source code) says:
A foreign key constraint requires that the key columns in the parent table are collectively subject to a UNIQUE or PRIMARY KEY constraint. […] If the required index cannot be found, either because:
- The named parent key columns do not exist, or
- The named parent key columns do exist, but are not subject to a UNIQUE or PRIMARY KEY constraint, or
- No parent key columns were provided explicitly as part of the foreign key definition, and the parent table does not have a PRIMARY KEY, or
- No parent key columns were provided explicitly as part of the foreign key definition, and the PRIMARY KEY of the parent table consists of a a different number of columns to the child key in the child table.
then … a "foreign key mismatch" error [is raised].
> DELETE FROM Child;
Error: foreign key mismatch
> CREATE UNIQUE INDEX di ON Department(DepartmentId);
> DELETE FROM Child;
>