#36592: Incorrect warning when specifying a UniqueConstraint with SQLite and
nulls_distinct=False
-------------------------------------+-------------------------------------
Reporter: r-owen | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SQLite | Triage Stage:
UniqueConstraint | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by r-owen:
Old description:
> I am trying to create a UniqueConstraint with `nulls_distinct=False`.
> This will be used with sqlite for local use and tests, and postgresql for
> production.
>
> When I migrate my sqlite database I get this warning:
> ```
> SQLite does not support unique constraints with nulls distinct.
> ```
> I suspect this is a bug, since I specified that nulls should not be
> distinct.
>
> Note that I also get the same warning if I specify `nulls_distinct=True`,
> but in that case I expect to see it.
>
> Here is the simplest model I could come up with that shows the issue:
> ```
> class SimpleModel(models.Model):
> field_a = models.IntegerField(null=True)
> field_b = models.IntegerField(null=True)
>
> class Meta:
> constraints = [
> UniqueConstraint(
> name="simple_unique_constraint",
> fields=["field_a", "field_b"],
> nulls_distinct=False,
> ),
> ]
> ```
> The full warning I see on migration is:
> ```
> WARNINGS:
> dances.SimpleModel: (models.W047) SQLite does not support unique
> constraints with nulls distinct.
> HINT: A constraint won't be created. Silence this warning if you
> don't care about it.
> ```
> and, as I said before, I get the same warning if I use
> `nulls_distinct=True` (which is when I expect to see the warning).
New description:
I am trying to create a UniqueConstraint with `nulls_distinct=False`. This
will be used with sqlite for local use and tests, and postgresql for
production.
When I migrate my sqlite database I get this warning:
{{{
SQLite does not support unique constraints with nulls distinct.
}}}
I suspect this is a bug, since I specified that nulls should not be
distinct.
Note that I also get the same warning if I specify `nulls_distinct=True`,
but in that case I expect to see it.
Here is the simplest model I could come up with that shows the issue:
{{{
class SimpleModel(models.Model):
field_a = models.IntegerField(null=True)
field_b = models.IntegerField(null=True)
class Meta:
constraints = [
UniqueConstraint(
name="simple_unique_constraint",
fields=["field_a", "field_b"],
nulls_distinct=False,
),
]
}}}
The full warning I see on migration is:
{{{
WARNINGS:
dances.SimpleModel: (models.W047) SQLite does not support unique
constraints with nulls distinct.
HINT: A constraint won't be created. Silence this warning if you
don't care about it.
}}}
and, as I said before, I get the same warning if I use
`nulls_distinct=True` (which is when I expect to see the warning).
--
--
Ticket URL: <
https://code.djangoproject.com/ticket/36592#comment:2>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.