Json Nullable改为JSON Array

环境

laravel framework 10.10
php 8.1
mysql 8.0

之前数据库字段为json(column)->nullable();
现在想改为json(column)->default(new Expression(‘(JSON_ARRAY())’));

$table->json("xxx")->default(new Expression('(JSON_ARRAY())'))->change();

报错如下

str_replace(): Argument #3 ($subject) must be of type array|string, Illuminate\Database\Query\Expression given

  at vendor/doctrine/dbal/src/Platforms/AbstractMySQLPlatform.php:1375
    1371* {@inheritDoc}
    1372*/
    1373public function quoteStringLiteral($str)
    1374{1375▕         $str = str_replace('\\', '\\\\', $str); // MySQL requires backslashes to be escaped
    13761377return parent::quoteStringLiteral($str);
    1378}
    1379

求大佬指点

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1

🤷‍♂️ 好像是不行


随便搜了一下,没有测试,应该这样就可以了吧

$table->json("xxx")->default('[]')->change();
1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!