With this orderitem table configuration (where user collects order products) i cant insert value correctly because as i said the same field Codart is in both table product and variants
So how can define the fk so the table accept product with and without a variant
I repeat: table product has all products (all codart values)
instead table variants has only products (codart) that has at least a variant (codvar);
Variant table not has for example a product that has no variant and that is stored in Product table but not in Variant
B1 is in table Variant with variants 1 and 2
So fk in Product (codart) not permit to add B1 with variants
CREATE TABLE OrderItem
(
Codart TEXT NOT NULL,
Codvar TEXT NOT NULL DEFAULT "",
Descri TEXT NOT NULL,
Quanty INT NOT NULL,
Price REAL NOT NULL,
...
CONSTRAINT PK_Riorcl PRIMARY KEY(...Codart,Codvar),
CONSTRAINT FK_Product FOREIGN KEY (Codart) REFERENCES Product(Codart),
CONSTRAINT FK_Variants FOREIGN KEY (Codart, Codvar) REFERENCES Variants(Codart,Codvar)
)