#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to