Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for foreign keys to composite primary keys #56

Open
edu-zamora opened this issue Mar 21, 2014 · 0 comments
Open

Add support for foreign keys to composite primary keys #56

edu-zamora opened this issue Mar 21, 2014 · 0 comments

Comments

@edu-zamora
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant