#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 , 9 years ago
Component: | Core (Management commands) → Core (System checks) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
comment:2 by , 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 , 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 , 9 years ago
Cc: | added |
---|
Please see the SILENCED_SYSTEM_CHECKS setting.
In the future, ask usage questions using our support channels linked from TicketClosingReasons/UseSupportChannels. Thanks!