Skip to content

feat(indexes): add nulls_not_distinct option to PostgreSQLIndex#2247

Open
pctablet505 wants to merge 2 commits into
tortoise:developfrom
pctablet505:fix-1641-nulls-not-distinct
Open

feat(indexes): add nulls_not_distinct option to PostgreSQLIndex#2247
pctablet505 wants to merge 2 commits into
tortoise:developfrom
pctablet505:fix-1641-nulls-not-distinct

Conversation

@pctablet505

@pctablet505 pctablet505 commented Jul 15, 2026

Copy link
Copy Markdown

Fixes #1641.

Adds unique and nulls_not_distinct parameters to PostgreSQLIndex, so users can create NULLS NOT DISTINCT unique indexes directly instead of relying on unique_together. This matches the approach discussed in the issue: keep unique_together unchanged and expose the option on the PostgreSQL-specific index class.

Adds regression tests for schema generation and migration SQL output.

Add unique and nulls_not_distinct parameters to PostgreSQLIndex so users
can create PostgreSQL unique indexes that treat NULL values as equal.
This implements the direction from abondar in tortoise#1641: expose the option
on tortoise.contrib.postgres.indexes.PostgreSQLIndex instead of changing
unique_together behavior.

Fixes tortoise#1641
Run make style to satisfy the ruff format and isort (I) checks so the
lint gate passes.
@pctablet505
pctablet505 marked this pull request as ready for review July 17, 2026 12:48
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

Successfully merging this pull request may close these issues.

unique indexes (for unique_together) on nullable columns need to be optionable for nulls not distinct

1 participant