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

Specify foreign key against compound key in other table #487

Closed
ryanfox opened this issue Sep 9, 2022 · 2 comments
Closed

Specify foreign key against compound key in other table #487

ryanfox opened this issue Sep 9, 2022 · 2 comments

Comments

@ryanfox
Copy link

ryanfox commented Sep 9, 2022

When inserting rows via the library, is it possible to specify a foreign key to a compound primary key?

For example, suppose I create a table:

db = Database('events.db')
db['events'].insert_all([
    {'venue': 'Times Square', 'date': '2022-12-31', 'title': 'Rockin New Year Eve'},
    {'venue': 'Wembley Stadium', 'date': '2022-06-05', 'title': 'FA Cup'},
    {'venue': 'Times Square', 'date': '2021-12-31', 'title': 'Rockin New Year Eve'},
], pk=('date', 'venue'))

And I want to add related data in another table:

act = {'name': 'Rick Astley', 'venue': 'Times Square', 'date': '2021-12-31' }
db['performers'].insert(act, pk=<???>)

Is it possible to specify a value for pk that will point to the compound primary key in events?

SQLite does support it:
https://www.sqlite.org/foreignkeys.html#fk_composite

@simonw
Copy link
Owner

simonw commented Sep 9, 2022

This isn't supported yet - there's an older issue for that here:

@ryanfox
Copy link
Author

ryanfox commented Sep 9, 2022 via email

sthagen pushed a commit to sthagen/simonw-sqlite-utils that referenced this issue Sep 10, 2022
@ryanfox ryanfox closed this as completed Sep 11, 2022
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

2 participants