Replace unique_together with UniqueConstraint #2581

Closed
opened 2025-12-29 18:20:07 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (May 3, 2019).

Proposed Changes

Replace all instances of unique_together under model Meta classes with an equivalent UniqueConstraint implementation.

Justification

Django 2.2 introduced constraints, and the unique_together Meta option will likely be deprecated in the near future.

Originally created by @jeremystretch on GitHub (May 3, 2019). ### Proposed Changes Replace all instances of `unique_together` under model Meta classes with an equivalent UniqueConstraint implementation. ### Justification Django 2.2 introduced [constraints](https://docs.djangoproject.com/en/2.2/ref/models/constraints/#uniqueconstraint), and the `unique_together` Meta option will likely be deprecated in the near future.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:20:07 +01:00
adam closed this issue 2025-12-29 18:20:07 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 8, 2019):

@hellerve did some great work on this. Unfortunately, adopting UniqueConstraint requires manually specifying a (often verbose) name for each constraint, as opposed to the auto-generated name provided by unique_together. Given that this would be a net-zero change and that unique_together is not currently marked for deprecation, let's avoid this for now. (It's not that we can't define a name for each, it's just one more thing to worry about.)

Hopefully Django will implement automatic naming for UniqueConstraints in a future release.

@jeremystretch commented on GitHub (Aug 8, 2019): @hellerve did some great work on this. Unfortunately, adopting `UniqueConstraint` requires manually specifying a (often verbose) name for each constraint, as opposed to the auto-generated name provided by `unique_together`. Given that this would be a net-zero change and that `unique_together` is not currently marked for deprecation, let's avoid this for now. (It's not that we _can't_ define a name for each, it's just one more thing to worry about.) Hopefully Django will implement automatic naming for UniqueConstraints in a future release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2581