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

Symfony Make Entity命令报错:Undefined class constant 'JSON_ARRAY'求助

解决Symfony make:entity命令中"Undefined class constant 'JSON_ARRAY'"错误

问题原因

该错误源于symfony/maker-bundle与Doctrine DBAL版本不兼容:高版本Doctrine DBAL(3.0+)已废弃JSON_ARRAY常量,改用JsonType::JSON_TYPE_ARRAY,但旧版本的maker-bundle仍在引用这个已移除的常量。

解决方案

1. 升级symfony/maker-bundle到兼容版本

执行以下命令安装适配当前DBAL版本的maker-bundle稳定版:

composer require symfony/maker-bundle:^1.50

若不确定兼容版本,可直接安装最新稳定版:

composer require symfony/maker-bundle --update-with-all-dependencies

2. 验证版本兼容性

运行以下命令查看当前包版本,确认两者适配:

composer show symfony/maker-bundle doctrine/dbal
  • Doctrine DBAL 3.x需搭配maker-bundle 1.40+版本
  • Doctrine DBAL 2.x可使用maker-bundle 1.40以下版本

3. 临时修复(不推荐,优先升级)

若无法立即升级,可手动修改maker-bundle代码:

  1. 打开vendor/symfony/maker-bundle/src/Maker/MakeEntity.php文件
  2. 定位到332行,将JSON_ARRAY替换为JsonType::JSON_TYPE_ARRAY
  3. 在文件顶部添加引用:
use Doctrine\DBAL\Types\JsonType;

4. 清除缓存后重试

执行缓存清除命令,再重新运行make:entity:

php bin/console cache:clear
php bin/console make:entity

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 01:25:13