[Django] #26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served by a OneToOneField."

59 views
Skip to first unread message

Django

unread,
Jan 6, 2016, 4:40:20 AM1/6/16
to django-...@googlegroups.com
#26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served
by a OneToOneField."
--------------------------------------------+--------------------
Reporter: srkunze | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Management commands) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+--------------------
When upgrading from Django 1.7 to Django 1.8 using the runserver command,
we noticed we get plenty of the following warnings:

mode.field_name: (fields.W342) Setting unique=True on a ForeignKey has the
same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a
OneToOneField.

We found that ForeignKey with unique scales usually better for two
reasons:

1) no need to handle None
2) changing from unique to non-unique is straight forward as one already
works with collections

Is there a way to suppress/remove that warning ?

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

Django

unread,
Jan 6, 2016, 6:17:43 AM1/6/16
to django-...@googlegroups.com
#26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served
by a OneToOneField."
-------------------------------------+-------------------------------------
Reporter: srkunze | Owner: nobody
Type: Uncategorized | Status: closed
Component: Core (System | Version: 1.8
checks) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: => 0
* component: Core (Management commands) => Core (System checks)
* needs_tests: => 0
* needs_docs: => 0
* resolution: => invalid


Comment:

Please see the [https://docs.djangoproject.com/en/stable/ref/settings/#std
:setting-SILENCED_SYSTEM_CHECKS SILENCED_SYSTEM_CHECKS] setting.

In the future, ask usage questions using our support channels linked from
TicketClosingReasons/UseSupportChannels. Thanks!

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

Django

unread,
Jan 6, 2016, 12:37:28 PM1/6/16
to django-...@googlegroups.com
#26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served
by a OneToOneField."
-------------------------------------+-------------------------------------
Reporter: srkunze | Owner: nobody

Type: Uncategorized | Status: closed
Component: Core (System | Version: 1.8
checks) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by srkunze):

Thanks for pointing me in that direction. However, we found that there is
no reason to recommend OneToOneField as system checks do. From our
perspective it encourages suboptimal design.

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

Django

unread,
Jan 6, 2016, 1:06:59 PM1/6/16
to django-...@googlegroups.com
#26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served
by a OneToOneField."
-------------------------------------+-------------------------------------
Reporter: srkunze | Owner: nobody

Type: Uncategorized | Status: closed
Component: Core (System | Version: 1.8
checks) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

There was some debate about it on the original ticket (#23338). If you
want it considered for removal, you should raise your argument on the
DevelopersMailingList.

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

Django

unread,
Jan 28, 2016, 3:12:36 AM1/28/16
to django-...@googlegroups.com
#26044: Misleading Warning "HINT: ForeignKey(unique=True) is usually better served
by a OneToOneField."
-------------------------------------+-------------------------------------
Reporter: srkunze | Owner: nobody

Type: Uncategorized | Status: closed
Component: Core (System | Version: 1.8
checks) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: tzanke@… (added)


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

Reply all
Reply to author
Forward
0 new messages