[Django] #31185: UniqueConstraint rises fields.E310 error because of issue with no backward compatibility with unique_together

27 views
Skip to first unread message

Django

unread,
Jan 20, 2020, 7:34:33 AM1/20/20
to django-...@googlegroups.com
#31185: UniqueConstraint rises fields.E310 error because of issue with no backward
compatibility with unique_together
-------------------------------------+-------------------------------------
Reporter: Pavel | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.2
Migrations | Keywords: UniqueConstraint,
Severity: Normal | unique_together
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello,

I'm trying to create migration with this kind of model.

{{{
class AppUsers(models.Model):
name = models.CharField(...)
uid = models.CharField(...)
source = models.ForeignKey(...)

class Meta:
constraints = [models.UniqueConstraint(fields=['uid', 'source'],
name='appusers_uniqueness')]
}}}

When I start ''makemigrations'' command in manage.py I've faced
fields.E310 [https://docs.djangoproject.com/en/2.2/ref/checks/#related-
fields] error

It says that I should add unique_together field in Meta options:
**app_name.AppUsers.field: (fields.E310) No subset of the fields 'uid',
'source' on model 'AppUsers' is unique.
HINT: Add unique=True on any of those fields or add at least a subset of
them to a unique_together constraint.**

If I change Meta options to unique_together constraint migration passes
with no errors.


{{{
class AppUsers(models.Model):
name = models.CharField(...)
uid = models.CharField(...)
source = models.ForeignKey(...)

class Meta:
unique_together = [['uid', 'source']]
}}}


As mentioned in docs
[https://docs.djangoproject.com/en/2.2/ref/models/options/#unique-
together] ''unique_together'' may be deprecated in the future. So I think
nobody wants to face this issue when this will be deprecated :)

Thanks,
Pavel

--
Ticket URL: <https://code.djangoproject.com/ticket/31185>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 20, 2020, 9:03:47 AM1/20/20
to django-...@googlegroups.com
#31185: UniqueConstraint rises fields.E310 error because of issue with no backward
compatibility with unique_together
-------------------------------------+-------------------------------------
Reporter: Pavel | Owner: nobody
Type: Bug | Status: new
Component: Core (System | Version: 2.2
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* keywords: UniqueConstraint, unique_together => UniqueConstraint
unique_together E310
* component: Migrations => Core (System checks)
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:1>

Django

unread,
Jan 20, 2020, 9:22:27 AM1/20/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: nobody
Type: Bug | Status: new
Component: Core (System | Version: master

checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* keywords: UniqueConstraint unique_together E310 => UniqueConstraint
unique_together E310 E311
* version: 2.2 => master


Comment:

Agreed, both checks should take into `UniqueConstraint`'s without
`condition`'s.

--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:2>

Django

unread,
Jan 24, 2020, 10:37:09 AM1/24/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned

Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad Abdallah):

* owner: nobody => Ahmad Abdallah
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:3>

Django

unread,
Feb 19, 2020, 4:20:55 AM2/19/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:4>

Django

unread,
Feb 19, 2020, 5:16:13 AM2/19/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ahmad Abdallah):

Posting a patch soon

--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:5>

Django

unread,
Feb 19, 2020, 5:42:02 PM2/19/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ahmad Abdallah):

[https://github.com/django/django/pull/12477 Patch] submitted. Let me know
what i need to improve. I haven't written a test it but I tested it on the
code snippet posted above and it worked

--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:6>

Django

unread,
Feb 19, 2020, 5:46:15 PM2/19/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad Abdallah):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:7>

Django

unread,
Feb 20, 2020, 6:10:28 AM2/20/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:8>

Django

unread,
Feb 24, 2020, 5:40:42 AM2/24/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:9>

Django

unread,
Feb 24, 2020, 4:03:06 PM2/24/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad Abdallah):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:10>

Django

unread,
Feb 25, 2020, 2:22:06 AM2/25/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:11>

Django

unread,
Feb 25, 2020, 10:03:23 AM2/25/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad Abdallah):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:12>

Django

unread,
Feb 26, 2020, 4:32:15 AM2/26/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Accepted
unique_together E310 E311 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ahmad Abdallah):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:13>

Django

unread,
Feb 27, 2020, 4:56:30 AM2/27/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: UniqueConstraint | Triage Stage: Ready for
unique_together E310 E311 | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:14>

Django

unread,
Feb 27, 2020, 5:33:38 AM2/27/20
to django-...@googlegroups.com
#31185: fields.E310-E311 should take into account UniqueConstraints without
conditions.
-------------------------------------+-------------------------------------
Reporter: Pavel Garkin | Owner: Ahmad
| Abdallah
Type: Bug | Status: closed

Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed

Keywords: UniqueConstraint | Triage Stage: Ready for
unique_together E310 E311 | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5bf28ac2ed17773214bd6c7796ef356067c9fa91" 5bf28ac2]:
{{{
#!CommitTicketReference repository=""
revision="5bf28ac2ed17773214bd6c7796ef356067c9fa91"
Fixed #31185 -- Fixed detecting of unique fields in
ForeignKey/ForeignObject checks when using Meta.constraints.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31185#comment:15>

Reply all
Reply to author
Forward
0 new messages