如果子查询引用基表,Django QuerySet.update()将在MySQL上失败
我正在尝试使此事务与mysql兼容。因为mysql不允许当前操作。MySQL不允许更新已在内部select中使用的表作为更新条件 获取此错误如果子查询引用基表,Django QuerySet.update()将在MySQL上失败,mysql,django,django-orm,django-oscar,django-mysql,Mysql,Django,Django Orm,Django Oscar,Django Mysql,我正在尝试使此事务与mysql兼容。因为mysql不允许当前操作。MySQL不允许更新已在内部select中使用的表作为更新条件 获取此错误 django.db.utils.OperationalError: (1093, "You can't specify target table 'catalogue_category' for update in FROM clause") 代码: 您可以自己进行子查询。将一个查询拆分为多个查询 e、 g included_in_n
django.db.utils.OperationalError: (1093, "You can't specify target table 'catalogue_category' for update in FROM clause")
代码:
您可以自己进行子查询。将一个查询拆分为多个查询 e、 g
included_in_non_public_子树=not self.\uuuuu class\uuuu.objects.filter(
is_public=False,path_urstartswith=OuterRef(“路径”),depth_ult=OuterRef(“深度”)
).exists()
self.get_和_self().update(
祖先是公共的=包含在非公共子树中,
)
您可以自己进行子查询。将一个查询拆分为多个查询
e、 g
included_in_non_public_子树=not self.\uuuuu class\uuuu.objects.filter(
is_public=False,path_urstartswith=OuterRef(“路径”),depth_ult=OuterRef(“深度”)
).exists()
self.get_和_self().update(
祖先是公共的=包含在非公共子树中,
)
您能提供一些提示吗?不起作用。给出此错误ValueError:此查询集包含对外部查询的引用,只能在子查询中使用。
@SobanJaved能否粘贴回溯或有关self的更多详细信息。\uuu class\uuuu
?能否提供任何提示?不工作。给出此错误ValueError:此查询集包含对外部查询的引用,只能在子查询中使用。
@SobanJaved能否粘贴回溯或有关self的更多详细信息。\uuuuu class\uuuuu
?
included_in_non_public_subtree = self.__class__.objects.filter(
is_public=False, path__rstartswith=OuterRef("path"), depth__lt=OuterRef("depth")
)
self.get_descendants_and_self().update(
ancestors_are_public=Exists(
included_in_non_public_subtree.values("id"), negated=True)
)