Opened 15 years ago

Closed 15 years ago

#12190 closed (fixed)

Changeset [11710] breaks ForeignKey.db_type for fields defined outside a model

Reported by: jittat Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: multi-db, ForeignKey
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When defining a ForeignKey field outside a model, ForeignKey.db_type produces an exception FieldDoesNotExist. This bug breaks south 0.6.2, and starts occurring after changeset [11710].

Steps to reproduce

  1. Assume that you already have a Poll model defined as in the tutorial
  1. In shell, do the following
from polls.models import Poll
from django.db import models
poll = models.ForeignKey(Poll)

You expect to see 'integer' (on revision [11709], you see it), but you'll get the following:

  File "<console>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/django/db/models/fields/", line 771, in db_type
    rel_field = self.rel.get_related_field()
  File "/usr/lib/python2.6/dist-packages/django/db/models/fields/", line 648, in get_related_field
    data =
  File "/usr/lib/python2.6/dist-packages/django/db/models/", line 299, in get_field_by_name
    % (self.object_name, name))
FieldDoesNotExist: Poll has no field named None

Additional information

After some tracing, I think this bug is related to the removal of line 693 in source:/django/trunk/django/db/models/fields/ in changeset [11710]. The following line is removed:

            to_field = to_field or 

Change History (2)

comment:1 by jittat, 15 years ago

Sorry, the link to the original file is wrong (it points to the file after the change of [11710]). The correct link is line 693 in source:/django/trunk/django/db/models/fields/

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [11730]) Fixed #12190 -- Corrected a regression in the ability to instantiate ForeignKeys? outside of models. Thanks to jittat for the report.

Note: See TracTickets for help on using tickets.
Back to Top