Skip to content

problem #2704

Description

@xinxianshui-crypto

Describe the bug
以下是一份可直接提交给 Coze 官方 GitHub Issues 的问题报告,你可以复制后直接粘贴使用。


[Bug] coze-server 容器反复重启:Table 'opencoze.model_instance' doesn't exist

问题描述

在 Windows 环境下使用 Docker Compose 部署 Coze Studio 开源版时,coze-server 容器反复重启,无法正常启动。日志显示数据库表 opencoze.model_instance 不存在,导致服务初始化失败并 panic。

环境信息

项目 信息
操作系统 Windows(Git Bash / MINGW64)
Docker Docker Desktop(WSL2 后端)
镜像 cozedev/coze-studio-server:latest
部署方式 docker compose --profile '*' up -d
数据库 MySQL 8.0.36(容器名:coze-mysql

复现步骤

  1. 克隆 Coze Studio 仓库并进入 docker 目录
  2. 按官方文档配置 .env 文件
  3. 执行 docker compose --profile '*' up -d
  4. 查看容器状态:docker ps,发现 coze-server 状态为 Restarting
  5. 查看日志:docker logs coze-server,出现以下错误

完整错误日志

2026/06/16 22:41:17.127354 main.go:111: [Info] load env file: .env
2026/06/16 22:41:17.127901 main.go:132: [Info] log level: debug
2026/06/16 22:41:17.142497 model_meta.go:82: [Info] use default model meta for model class SEED and model name

2026/06/16 22:41:17 /app/bizpkg/config/modelmgr/model_get.go:205 Error 1146 (42S02): Table 'opencoze.model_instance' doesn't exist
[2.490ms] [rows:0] SELECT * FROM `model_instance` WHERE `model_instance`.`id` = 100001 ORDER BY `model_instance`.`id` LIMIT 1
panic: InitializeInfra failed, err=init model config failed, err=get model by id failed, err: Error 1146 (42S02): Table 'opencoze.model_instance' doesn't exist

goroutine 1 [running]:
main.main()
        /app/main.go:55 +0x86

其他服务状态

docker ps 输出显示所有依赖服务均正常运行:

coze-mysql     Up (healthy)
coze-minio     Up (healthy)
coze-es        Up (healthy)
coze-milvus    Up

只有 coze-server 处于 Restarting 状态。

尝试过的解决方案(均无效)

尝试的方案 结果
docker-compose.yml 中设置 AUTO_MIGRATE=true 无效,环境变量未被识别
添加 DB_HOST=mysqlDB_USER=root 等环境变量 无效
尝试 ./opencoze migrate 手动迁移 失败,程序在迁移前就检查表是否存在
尝试 ./opencoze --help 失败,同样因表缺失而 panic
检查并删除 .env 文件避免干扰 无效
修改容器名称从 coze-mysqlmysql 无效
添加 MYSQL_USER=cozeMYSQL_PASSWORD=coze123 创建数据库用户 无效
进入容器内部检查文件结构 发现容器内无 migrations/ 目录,无迁移脚本

关键观察

  1. “先有鸡还是先有蛋”的死循环./opencoze 在启动时会强制检查 model_instance 表是否存在。表不存在 → 程序 panic → 无法执行任何命令(包括 migrate--help)。这意味着用户无法通过任何内置命令来创建缺失的表。

  2. 没有独立的迁移脚本:进入容器后执行 ls -la,发现容器内没有 migrations/ 目录,也没有独立的 SQL 初始化脚本。唯一的可执行文件是 opencoze 本身。

  3. 其他类似问题:GitHub Issues 中已有类似问题,如 plugin_draft 表不存在和 workflow_version 表不存在。这些问题的解决方案都是手动处理权限或删除数据目录后重启,说明数据库初始化流程存在不稳定性。

  4. AUTO_MIGRATE 环境变量无效:设置 AUTO_MIGRATE=true 后,日志中没有任何迁移相关的输出,该变量似乎未被程序识别。

期望行为

coze-server 容器启动时应能自动检测并创建缺失的数据库表,或者在镜像中包含独立的迁移脚本/工具,允许用户在容器启动前手动初始化数据库。

建议修复方向

  1. 提供独立的迁移工具:在镜像中内置 migrate 命令,使其不依赖表是否存在即可执行
  2. 完善 AUTO_MIGRATE 机制:让该环境变量真正生效,在服务启动前自动完成表结构创建
  3. 在镜像中预置 SQL 初始化脚本:提供独立的 .sql 文件,用户可通过 docker exec 手动执行
  4. 改进启动逻辑:当表不存在时,自动创建而非直接 panic

额外信息

  • 此问题在 Windows 环境下出现,社区中有类似案例
  • 社区其他用户也遇到类似“表不存在”的问题,通常是因为 mysql-setup-schema 容器未成功运行
  • 当前镜像版本可能缺少完整的数据库初始化流程

提交位置https://github.com/coze-dev/coze-studio/issues/new/choose

选择 Bug report 模板,将以上内容粘贴即可。
A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Version:

Please provide the version of {project_name} you are using.

Environment:

The output of go env.

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions