ForeignKey field and Multiple database bug
|Reported by:||vital.fadeev@…||Owned by:||nobody|
|Severity:||Normal||Keywords:||ForeignKey, multiple database|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I get error "Incorrect table name" when I save entry.
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]
(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.
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
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