Django ValueError: Unable to execute subqueries with queries across different db

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'default_db',
'USER': 'user',
    'PASSWORD': '123123123',
    'HOST': 'localhost',
'PORT': '',
},
'omskgkh': {
    'NAME': 'general',
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'USER': 'user',
    'PASSWORD': '123123123',
    'HOST': '123.123.123.123',
    'PORT': '',
}}

      

in my opinion:

def districtreport(request):

info = models.InfoAddress.objects.using('general')
kao = info.filter(okrug='').values('home')

kao_accounts = models.Operation.objects.using('general').filter(account_id__home_id=kao)

      

On dev server with (default database is sqlite3) which view is fine, but on Django production server raise

Exception value: it is impossible to execute subqueries with queries in different databases.

Please, help.

ADD : models.py

class Home(models.Model):
  id = models.IntegerField(primary_key=True)
  ...

  class Meta:
      db_table = "home"
      managed = False


class InfoAddress(models.Model):
    id = models.IntegerField(primary_key=True)
    home = models.ForeignKey(Home)
    okrug = models.CharField(max_length=255)
    ...

class Meta:
    db_table = "infoaddress"
    managed = False


class Account(models.Model):
    id = models.IntegerField(primary_key=True)
    home = models.ForeignKey(Home)
    ...

class Meta:
    db_table = "account"
    managed = False


class Operation(models.Model):
    id = models.IntegerField(primary_key=True)
    account = models.ForeignKey(Account)
    ...

class Meta:
    db_table = "account_op"
    managed = False

      

+3


source to share


3 answers


I found one way to solve the problem: Modify the QuerySet to view and filter it.



+1


source


Caching update 2.4.1 or newer will be fixed.



A related issue has now been fixed.

0


source


The problem was caused by the "cacheops" application. Corrected by the author.

-1


source







All Articles