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

Heroku部署Django多租户应用执行migrate_schemas遇KeyError: 'skip_checks'

解决方案:修复migrate_schemas --shared执行时的KeyError: 'skip_checks'错误

这个错误是因为django-tenant-schemas版本与Django 3.0不兼容导致的:Django 3.0的MigrateCommand.execute()方法新增了skip_checks参数,但你当前使用的tenant-schemas版本未传递该参数,从而触发KeyError。

方法一:升级兼容版本的多租户库

django-tenant-schemas后续已更名为django-tenants,且该项目已适配Django 3.x及以上版本。直接更换依赖即可解决问题:

  • 修改requirements.txt文件:
    django-tenants>=3.0.0
    
  • 重新部署到Heroku,确保依赖安装完成后,再次执行迁移命令:
    heroku run python manage.py migrate_schemas --shared
    

方法二:临时源码修改(不推荐长期使用)

若暂时无法升级依赖,可手动修改tenant-schemas的源码:

  1. 找到/app/.heroku/python/lib/python3.10/site-packages/tenant_schemas/migration_executors/base.py文件中报错的第31行
  2. 在调用execute方法时添加skip_checks=False参数,修改后代码如下:
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, skip_checks=False, **options)
    
  3. 重新执行迁移命令即可。

额外提示

  • 部署前务必保证本地开发环境与Heroku的Django版本、依赖版本一致,避免环境差异引发问题。
  • 若更换为django-tenants,需同步调整项目中相关导入路径(如从tenant_schemas改为django_tenants)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 15:06:16