You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用django-tenants通过call_command运行指定schema自定义命令报错求助

解决django-tenants中call_command调用tenant_command报错的问题

报错原因

你调用call_command时存在两个问题:

  1. 参数名错误:终端里的--schema对应tenant_command的参数名是schema,而非你使用的schema_name;
  2. 子命令传递方式触发内部处理错误,导致命令名被识别为列表类型,从而抛出unhashable type: 'list'错误。

正确调用方式

以下几种写法均可正常运行:

方式一:直接传递子命令+指定schema参数

from django.core.management import call_command

call_command('tenant_command', 'load_user_groups', schema=schema_name)

方式二:通过args参数传递所有子命令和选项

call_command('tenant_command', args=['load_user_groups', f'--schema={schema_name}'])

方式三:显式指定command参数

call_command('tenant_command', command=['load_user_groups'], schema=schema_name)

内容的提问来源于stack exchange,提问作者stackuser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 05:16:06