You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using @PrimaryKey annotation in multiple fields of a class will create a composite primary key, but is there any way to create foreign key to point to that composite primary key?
As far as I know, we can only add a @foreignkey annotation to a specific field, which will only point to a part of the composite primary key, and therefore, fail.
Another alternative would be to, instead of creating a composite primary key, use @AutoIncrementPrimaryKey and add a multiple column unique constraint to the columns that were included in the composite primary key.
Unfortunately, I don't see a way to do that either. I opened an issue here: #55
For now, what would be the best way to ensure for a table that the combination of two columns is unique?
Could I add that constraint manually in the table (using migration.addRawStatement?)?
Thanks a lot for your work, I am enjoying the library so far! :)
Using @PrimaryKey annotation in multiple fields of a class will create a composite primary key, but is there any way to create foreign key to point to that composite primary key?
As far as I know, we can only add a @foreignkey annotation to a specific field, which will only point to a part of the composite primary key, and therefore, fail.
Another alternative would be to, instead of creating a composite primary key, use @AutoIncrementPrimaryKey and add a multiple column unique constraint to the columns that were included in the composite primary key.
Unfortunately, I don't see a way to do that either. I opened an issue here:
#55
For now, what would be the best way to ensure for a table that the combination of two columns is unique?
Could I add that constraint manually in the table (using migration.addRawStatement?)?
Thanks a lot for your work, I am enjoying the library so far! :)
EDIT:
It seems that constraints cannot be added after table creation with sqlite:
http://stackoverflow.com/questions/1884818/how-do-i-add-a-foreign-key-to-an-existing-sqlite-3-6-21-table
The text was updated successfully, but these errors were encountered: