[Django] #17875: ForeignKey field and Multiple database bug

12 views
Skip to first unread message

Django

unread,
Mar 12, 2012, 4:41:14 AM3/12/12
to django-...@googlegroups.com
#17875: ForeignKey field and Multiple database bug
-------------------------------+-------------------------------------------
Reporter: | Owner: nobody
vital.fadeev@… | Status: new
Type: Bug | Version: 1.2
Component: Uncategorized | Keywords: ForeignKey, multiple database
Severity: Normal | Has patch: 1
Triage Stage: Unreviewed | UI/UX: 0
Easy pickings: 0 |
-------------------------------+-------------------------------------------
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).[[BR]]
I get error while save. [[BR]]
When trace I see variables who using '''db2'''. [[BR]]
And SQL-requests going to '''db2'''.[[BR]]
[[BR]]

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


== Solution: ==
(Please, say me right I or no)[[BR]]
ForeignKey field in '''validate()''' function using database from field
instance class. [[BR]]
But need using from related class.[[BR]]


{{{
using = router.db_for_read(model_instance.__class__,
instance=model_instance)
}}}
[[BR]]

(please, see attachment - patch)


I see it in 1.2, 1.3, 1.4rc1.

--
Ticket URL: <https://code.djangoproject.com/ticket/17875>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 12, 2012, 6:32:55 AM3/12/12
to django-...@googlegroups.com
#17875: ForeignKey field and Multiple database bug
-------------------------------------+-------------------------------------
Reporter: vital.fadeev@… | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.2
Severity: Normal | Resolution: wontfix
Keywords: ForeignKey, | Triage Stage:
multiple database | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* needs_docs: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

By design, Django doesn't support foreign keys across databases. See
[https://docs.djangoproject.com/en/dev//topics/db/multi-db/#limitations-
of-multiple-databases the docs] for more information on this design
decision.

--
Ticket URL: <https://code.djangoproject.com/ticket/17875#comment:1>

Django

unread,
Jun 14, 2014, 9:04:39 PM6/14/14
to django-...@googlegroups.com
#17875: ForeignKey field and Multiple database bug
-------------------------------------+-------------------------------------
Reporter: vital.fadeev@… | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution:

Keywords: ForeignKey, | Triage Stage:
multiple database | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by luis.kaufmann.silva@…):

* status: closed => new
* version: 1.2 => 1.6
* resolution: wontfix =>


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/17875#comment:2>

Django

unread,
Jun 14, 2014, 9:26:48 PM6/14/14
to django-...@googlegroups.com
#17875: ForeignKey field and Multiple database bug
-------------------------------------+-------------------------------------
Reporter: vital.fadeev@… | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution: wontfix

Keywords: ForeignKey, | Triage Stage:
multiple database | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by luiskaufmannsilva):

* status: new => closed

* resolution: => wontfix


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/17875#comment:3>

Django

unread,
Aug 18, 2015, 1:18:51 PM8/18/15
to django-...@googlegroups.com
#17875: ForeignKey field and Multiple database bug
-------------------------------------+-------------------------------------
Reporter: vital.fadeev@… | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution: wontfix
Keywords: ForeignKey, | Triage Stage:
multiple database | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gcko):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/17875#comment:4>

Reply all
Reply to author
Forward
0 new messages