* owner: nobody => Moez Saidi
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: Moez Saidi => Willem Van Onsem
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16524 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:3>
Comment (by Waqar ALi):
I believe you're confusing model meta option `constratins` with
`unique_together`. `UniqueConstraint` is a DB constraint assigned to
constraints option in Meta whereas unique together is another option on
Meta level.
{{{
class Mymodel(model):
class Meta:
unique_together = [ 'field1', 'field2' ]
constratints = [ UniqueConstraint ]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:4>
Comment (by Willem Van Onsem):
Replying to [comment:4 Waqar ALi]:
No, Django had in the early days `unique_together`, now it still has, but
as the note on the documentation says
(https://docs.djangoproject.com/en/4.1/ref/models/options/#django.db.models.Options.unique_together):
> Use `UniqueConstraint` with the constraints option instead.
It "translated" to a unique constraint. But it was less flexible since one
could not give it a custom name, add a condition, make it a functional
unique constraint, etc. So `UniqueConstraint` is the "new way" to define
this, whereas `unique_together` is the "old" way to generate such database
constraint.
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:5>
Old description:
> Documentation on serialization uses `unique_together`, whereas it seems
> to be advised to use Django's constraint framework. Therefore this might
> introduce confusion. Perhaps we should "update" the documentation.
>
> https://docs.djangoproject.com/en/dev/topics/serialization/
New description:
The idea is thus to transform code on the page like:
{{{
class Mymodel(model):
class Meta:
unique_together = [[ 'field1', 'field2' ]]
}}}
to:
{{{
class Mymodel(model):
class Meta:
constraints = [models.UniqueConstraint(fields=('field1',
'field2'), name='field1_2_unique')]
}}}
--
Comment (by Willem Van Onsem):
The idea is thus to transform code on the page like:
{{{
class Mymodel(model):
class Meta:
unique_together = [[ 'field1', 'field2' ]]
}}}
to:
{{{
class Mymodel(model):
class Meta:
constraints = [models.UniqueConstraint(fields=('field1',
'field2'), name='field1_2_unique')]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"292aacaf6c3d6956ca2c51c41e36dbf425389346" 292aaca]:
{{{
#!CommitTicketReference repository=""
revision="292aacaf6c3d6956ca2c51c41e36dbf425389346"
Fixed #34311 -- Updated serialization docs from unique_together to
UniqueConstraint.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:9>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"7a88b1f5aaea0c52e16aabbdd7a8ea57ca0f6aea" 7a88b1f]:
{{{
#!CommitTicketReference repository=""
revision="7a88b1f5aaea0c52e16aabbdd7a8ea57ca0f6aea"
[4.2.x] Fixed #34311 -- Updated serialization docs from unique_together to
UniqueConstraint.
Backport of 292aacaf6c3d6956ca2c51c41e36dbf425389346 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34311#comment:10>