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

Compound unique indexes #1045

Open
Forceres opened this issue Jul 5, 2024 · 2 comments
Open

Compound unique indexes #1045

Forceres opened this issue Jul 5, 2024 · 2 comments

Comments

@Forceres
Copy link

Forceres commented Jul 5, 2024

Is here a way to create compound unique indexes and use them in insert.on_conflict(target=unique_constraint)?

@sinisaos
Copy link
Member

sinisaos commented Jul 6, 2024

@Forceres You can use unique constraints in the on_conflict target argument as described here, but you need to add unique=True to each separate column in the table definition. The issue with adding a composite unique constraint to multiple columns at once will be resolved by this PR. For now, the workaround is to use raw sql (in migrations or script) to add a composite unique constraint, as described here.

@Forceres
Copy link
Author

Forceres commented Jul 8, 2024

@Forceres You can use unique constraints in the on_conflict target argument as described here, but you need to add unique=True to each separate column in the table definition. The issue with adding a composite unique constraint to multiple columns at once will be resolved by this PR. For now, the workaround is to use raw sql (in migrations or script) to add a composite unique constraint, as described here.

Yeah, made compound indexes via raw SQL (not a good approach)

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