0

I have two databases:

   DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'new',
        'USER': 'xxxxx',
        'PASSWORD': 'xxxxx',
        'HOST': '',
        'PORT': '',
    },
    'old': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'old',
        'USER': 'xxxxx',
        'PASSWORD': 'xxxxx',
        'HOST': '',
        'PORT': '',
    },
}

and model:

class MyModel(models.Model):
    user = models.ForeignKey(User)
    title = models.CharField(max_length=200)
    text = models.TextField()
    data = some other data

Old database contains some removed entries and some of the new database.How to filter entries from new database that there are no entries from the old database?

Nips
  • 13,162
  • 23
  • 65
  • 103
  • It's not currently supported, unless you "fake" it in certain cases: https://docs.djangoproject.com/en/dev/topics/db/multi-db/#limitations-of-multiple-databases – Cloud Artisans Nov 23 '14 at 17:36

1 Answers1

1

I made this:

f1 = MyModel.objects.using('old').all()

pids = [p.id for p in f1]

f2 = MyModel.objects.exclude(id__in=pids).filter()

But I don't know if it is good.

Nips
  • 13,162
  • 23
  • 65
  • 103