SQLite Forum

Please explain the error on insert
Login
In a relational database system (of which SQLite3 is one implementation) the parent:child relationship is a 1:N relationship.  Parents must be unique in their domain.  You can have more than one child per parent. A child in a relationship must have exactly exactly one parent or must be a bastard (the parent is unknown within the domain, hence NULL).

From this you can gleen the following rules:

 - The set of columns which comprise the "parent key" must be constrained unique -- this is done with the UNIQUE constraint or a UNIQUE index.  Furthermore, these values cannot be null (hence the parent key is a proper candidate key).

 - The set of children which belong to a parent must be able to be located.  This means that you usually want to have an index that begins with these "child key" columns unless you want to be complaining why referential enforcement is slow.

 - Children with no parents have the child key elements set to NULL (hence ON DELETE SET NULL).  If a child key cannot be null then the child *must* have a parent.

Your particular problem is that you have violated the first requirement (a unique index on the parent keys) and this is what the error message is telling you.  

Your database does not have integrity because it violates the last rule.