不确定这是否是一个错误,但是当将列类型从 varchar 更改为 json 时会导致以下错误:
Schema::table('fields', function (Blueprint $table) {
$table->json('label')->change();
});
[Doctrine\DBAL\DBALException]
Unknown column type "json" requested. Any Doctrine type that you use has to be registered
with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with
\Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspecti
on then you might have forgot to register all database types for a Doctrine Type. Use Abst
ractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMap
pedDatabaseTypes(). If the type name is empty you might have a problem with the cache or f
orgot some mapping information.
改用$table->text('label')->change();
吗?
问题在于 Doctrine DBAL,它还不支持 MySQL 的 JSON 列类型:
https://github.com/doctrine/dbal/blob/2.0.x/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L598
我目前看不到任何 PR,但您可以添加自定义地图类型(如错误消息中的建议):
即使我使用的是使用 Laravel 5.3 的 PostgreSQL 数据库,我也会收到此错误
$query = "ALTER TABLE fields MODIFY label
JSON DEFAULT NULL";
\Illuminate\Support\Facades\DB::statement($query);
在 laravel 迁移中试试这个.. 为我工作
最有用的评论
即使我使用的是使用 Laravel 5.3 的 PostgreSQL 数据库,我也会收到此错误