Laravel 数据库迁移时renameColumn报错

问题概述

在执行数据库迁移的时候遇到对json类型字段重命名报错,错误如下:

In AbstractPlatform.php line 454:

  Unknown database type json requested, Doctrine\DBAL\Platforms\MySqlPlatform  
   may not support it.

这是由于 $table->renameColumn('old', 'new')这行代码导致,在查阅文档后了解到 laravel 的迁移依赖于doctrine/dbal,这个包,搜索后发现网上的方法多是将json字段改为string处理,详见:“Unknown database type json requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.” while running php artisan migrate command ,但是若数据库原生支持json类型这种方法明显不是一个好的方法,治标不治本。

解决方案

其实我们只需要修改一下 config/database.php 配置文件即可。

 'mysql' => [
     ...
     'server_version' => "5.7", //增加这个声明一下数据库版本
     ...
]
点赞