Laravel Class Doctrine\DBAL\Driver\PDOMySql\Driver not found

Laravel: 5.5.*

在迁移中有重命名操作的时候,运行 php artisan migrate 会提示 Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found的错误信息,

可通过composer 安装 doctrine/dbal 类库,然后运行 迁移就可以了


修改 表字段的 enum值时,使用DB::statement() 方法进行修改字段的ENUM值

migration 文件中有以下代码:

1
2
3
4
5
6
7
8
9
Schema::table('users', function (Blueprint $table) {
if (Schema::hasColumn('users', 'social')) {
$table->enum('social',[
'weibo',
'zhihu',
'qq'
])->default('weibo')->index()->change();
}
});

运行 php artisan migrate 显示以下错误信息:

1
2
In AbstractPlatform.php line 434:   
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

migration 改为:

1
2
3
4
5
Schema::table('users', function (Blueprint $table) {
if (Schema::hasColumn('users', 'social')) {
DB::statement("ALTER TABLE users MODIFY COLUMN social ENUM('weibo','zhihu','qq')");
}
});

然后运行php artisan migrate 就可以修改到 用户表中的social的 enum 值

Reference
  1. 关于laravel renameColumn 更改字段报错
  2. [Bug] Schema builder - renameColumn fails on table with enum columns