Opened 11 years ago

Closed 8 years ago

Last modified 7 years ago

#17875 closed Bug (wontfix)

ForeignKey field and Multiple database bug

Reported by: vital.fadeev@… Owned by: nobody
Component: Uncategorized Version: 1.6
Severity: Normal Keywords: ForeignKey, multiple database
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no




I get error "Incorrect table name" when I save entry.


I have two models:

# db1
class User(models.Model):
  id = models.PositiveIntegerField(primary_key=True)

# db2
class Realtor(models.Model):
  realtor_id = ForeignKey(User)

where 'User' in using 'db1' and 'Realtor' using 'db2' (via router).
I get error while save.
When trace I see variables who using db2.
And SQL-requests going to db2.

I.e. SQL-requests runned on Realtor's database - 'db2'
(in db2 no table 'User' and I get 'Incorrect table name' error)[[BR]


(Please, say me right I or no)
ForeignKey field in validate() function using database from field instance class.
But need using from related class.

using = router.db_for_read(model_instance.__class__, instance=model_instance)

(please, see attachment - patch)

I see it in 1.2, 1.3, 1.4rc1.

Attachments (1)

foreignkey-db-using.patch (933 bytes) - added by vital.fadeev@… 11 years ago.

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by vital.fadeev@…

Attachment: foreignkey-db-using.patch added

comment:1 Changed 11 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

By design, Django doesn't support foreign keys across databases. See the docs for more information on this design decision.

comment:2 Changed 8 years ago by luis.kaufmann.silva@…

Resolution: wontfix
Status: closednew
Version: 1.21.6

In version 1.6.5 this bug still exists, this solution was distributed?

comment:3 Changed 8 years ago by luiskaufmannsilva

Resolution: wontfix
Status: newclosed

I'm an noob,i did not read the explanation in the 'wontfix'. Even do not agreeing with 'wontfix', sorry me by reopen the task.

comment:4 Changed 7 years ago by Jared Scott

I Created a gist around this ticket that subclasses ForeignKey. No need for a code change to django:

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