Opened 6 years ago

Closed 6 years ago

#17868 closed Uncategorized (invalid)

Multiple database and AutocompleteForeignKey = 'incorrect table name'

Reported by: vital.fadeev@… 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 Aymeric Augustin)

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.


  • table USERS_V


  • table realtors


class Realtor(models.Model):
    realtor_id = AutocompleteForeignKey(User, db_column='realtor_id',
    class Meta:
        db_table = 'realtors'

# Oracle
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
            return fallback
    def db_for_read(self, model, **hints):
        if model in using_map:
            return using_map[model]['db_read']
            return self._by_applabel(model, **hints)
    def db_for_write(self, model, **hints):
        if model in using_map:
            return using_map[model]['db_write']
            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 Changed 6 years ago by Aymeric Augustin

Description: modified (diff)
Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top