Opened 13 years ago

Closed 11 years ago

Last modified 9 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

Description

Hello.

Problem:

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

Details:

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]

Solution:

(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@… 13 years ago.

Download all attachments as: .zip

Change History (5)

by vital.fadeev@…, 13 years ago

Attachment: foreignkey-db-using.patch added

comment:1 by Aymeric Augustin, 13 years ago

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 by luis.kaufmann.silva@…, 11 years ago

Resolution: wontfix
Status: closednew
Version: 1.21.6

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

comment:3 by luiskaufmannsilva, 11 years ago

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 by Jared Scott, 9 years ago

I Created a gist around this ticket that subclasses ForeignKey. No need for a code change to django: https://gist.github.com/gcko/de1383080e9f8fb7d208

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