Opened 3 years ago

Closed 14 months 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@… 3 years ago.

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by vital.fadeev@…

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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

comment:2 Changed 14 months ago by luis.kaufmann.silva@…

  • Resolution wontfix deleted
  • Status changed from closed to new
  • Version changed from 1.2 to 1.6

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

comment:3 Changed 14 months ago by luiskaufmannsilva

  • Resolution set to wontfix
  • Status changed from new to closed

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.

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