Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26044 closed Uncategorized (invalid)

Misleading Warning "HINT: ForeignKey(unique=True) is usually better served by a OneToOneField."

Reported by: Sven R. Kunze Owned by: nobody
Component: Core (System checks) Version: 1.8
Severity: Normal Keywords:
Cc: tzanke@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 ?

Change History (4)

comment:1 by Tim Graham, 9 years ago

Component: Core (Management commands)Core (System checks)
Resolution: invalid
Status: newclosed

Please see the SILENCED_SYSTEM_CHECKS setting.

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

comment:2 by Sven R. Kunze, 9 years ago

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.

comment:3 by Tim Graham, 9 years ago

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.

comment:4 by TZanke, 9 years ago

Cc: tzanke@… added
Note: See TracTickets for help on using tickets.
Back to Top