Document restrictions on fields that can be referenced by ForeignKey.to_field
As someone who's never used the feature before (I looked at the documentation while investigating something else), it's not clear to me if there are limitations or restrictions on what kind of fields can be used?
For example, does it need to be an IntegerField
or can it be any field (trying it out, it seems that a CharField
works without issues).
One restriction which is caught by Django's validation framework is that the field needs to have unique=True
(this is the error fields.E311) but I don't know if there are more.
Change History
(5)
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to Jonatas CD
|
Status: |
new → assigned
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Based on a search into the code, you can find uses with
CharField
,EmailField
,IntegerField
,PositiveIntegerField
,UUIDField
.But in all cases indeed the referenced field has to be
unique=True
. Apart from that I didn't see any other restriction.Patch added updating documentation.