#17868: Multiple database and AutocompleteForeignKey = 'incorrect table name'
-------------------------------------+-------------------------------------
Reporter: vital.fadeev@… | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.2
Severity: Normal | Resolution: invalid
Keywords: multidb, | Triage Stage:
AutocompleteForeignKey, using | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):
* status: new => closed
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => invalid
Old description:
> 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?
New description:
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?
--
Comment:
Fixed formatting -- please use preview.
This looks more like a support request than a bug in Django => see
TicketClosingReasons/UseSupportChannels.
`AutocompleteForeignKey` isn't part of Django; it's probably provided by
some third party library. That said, foreign keys across databases won't
work anyway — MySQL can't guarantee integrity with an Oracle database and
vice versa.
--
Ticket URL: <https://code.djangoproject.com/ticket/17868#comment:1>
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.