I\'m tying to create a database in Android Room with two foreign keys. Every time I try to insert a track into the database the program chrashes and says that the \"foreign
You need to have rows in tables Kategorie
and Playlist
with a same foreign key as has Track
that you are inserting.
There's another reason why this error occurs which consumed a lot of my time since every possible solution available on the internet seemed futile in my case.
If you use rowId of the parent table as the parentColumn key, the Foreign key constraint CANNOT be used.
As per the SQLite documentation on Foreign Keys:
The parent key is the column or set of columns in the parent table that the foreign key constraint refers to. This is normally, but not always, the primary key of the parent table. The parent key must be a named column or columns in the parent table, not the rowid.