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

求大佬指点

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

🤷‍♂️ 好像是不行


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

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