#17868: Multiple database and AutocompleteForeignKey = 'incorrect table name'
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
vital.fadeev@… | Status: new
Type: | Version: 1.2
Uncategorized | Keywords: multidb, AutocompleteForeignKey,
Component: | using
Uncategorized | Has patch: 0
Severity: Normal | UI/UX: 0
Triage Stage: |
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
I need your help.
I describe two models. One in MySQL. And one in Oracle.
While save I get error: (1103, Incorrect table name USERS_V)
I.e. model 'User' look in to MySQL.
Databases:
Oracle
- table USERS_V
MySQL
- table realtors
Models:
# MySQL
class Realtor(models.Model):
realtor_id = AutocompleteForeignKey(User, db_column='realtor_id',
primary_key=True,
verbose_name=u'Realtor')
class Meta:
db_table = 'realtors'
# Oracle
@using('fe_test')
class User(models.Model):
id_user = models.PositiveIntegerField(u'ID', db_column='id_user',
primary_key=True)
class Meta:
db_table = "USERS_V"
My router:
class Router(object):
def _by_applabel(self, model, **hints):
app_label = model._meta.app_label
if app_label in settings.DATABASES:
return app_label
else:
return fallback
def db_for_read(self, model, **hints):
if model in using_map:
return using_map[model]['db_read']
else:
return self._by_applabel(model, **hints)
def db_for_write(self, model, **hints):
if model in using_map:
return using_map[model]['db_write']
else:
return self._by_applabel(model, **hints)
def allow_relation(self, obj1, obj2, **hints):
return True
# Model Decorator "using"
using_map = {}
def using(db_read, db_write=None):
"""
Model class decorator for directing into specific databases.
"""
if db_write is None:
db_write = db_read
def using_decorator(model):
using_map[model] = {
'db_read': db_read,
'db_write': db_write,
}
return model
return using_decorator
I use decorator 'using'. It work. But not work with AutocompleteForeignKey
Fields.
What I can do for solve this task?
--
Ticket URL: <https://code.djangoproject.com/ticket/17868>
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.