Opened 13 years ago
Closed 13 years ago
#17868 closed Uncategorized (invalid)
Multiple database and AutocompleteForeignKey = 'incorrect table name'
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | 1.2 |
Severity: | Normal | Keywords: | multidb, AutocompleteForeignKey, using |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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?
Change History (1)
comment:1 by , 13 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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.