#17875 closed Bug (wontfix)
ForeignKey field and Multiple database bug
Reported by: | 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)
Change History (5)
by , 13 years ago
Attachment: | foreignkey-db-using.patch added |
---|
comment:1 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 11 years ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
Version: | 1.2 → 1.6 |
In version 1.6.5 this bug still exists, this solution was distributed?
comment:3 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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.
comment:4 by , 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
By design, Django doesn't support foreign keys across databases. See the docs for more information on this design decision.