问题
I need to check a table from a remote db and update another table in my db. The models have same fields but checking with difference method will return an error:
qs1 get the data from one postgresql db
qs2 get the data from one mysql db
qs1 = (Local.objects
.values_list('ref')
)
qs2 = (Remote.objects
.filter()
.values_list('ref'))
>>> qs1.difference(qs1, qs2)
DatabaseError: intersection not supported on this database backend.
回答1:
I'm not exactly sure what you think your code is doind.
qs1 looks for a model Local in your default Databasengine. And qs2 looks for a model Remote also in your default Databasengine.
What you might want to do is defining a second Database in your settings.py naming it for Instance "remote" and then modify your q2 as follows :
qs2 = (Remote.objects.using("remote").filter().values_list('ref'))
This tells django that it shall contact your remote Database not your Local one.
Lemme know wether this helps or not.
回答2:
check = Qs1.objects.all()
prg=[]
[prg.append(x.ref) for x in check]
difference = (Qs2.objects
.exclude(ref__in=prg)
.values()
)
Maybe it's not elegant, but it just works.
来源:https://stackoverflow.com/questions/47282190/django-qs1-differenceqs2-qs3-not-supported-by-backend