您根本不应该使用枚举。
Laravel 5.1官方文档指出:
注意:目前不支持使用enum列重命名表中的列。
当您的数据库表中有enum列时,就会发生这种情况。 无论您是尝试将rename换成另一列,还是将另一列更改为nullable,都会出现该错误。 这是Doctrine \ DBAL的问题。
请求了未知的数据库类型枚举
即使使用laravel 5.8,问题也无法解决。
我需要补充一点,将可用选项添加到enum列声明中时,您将遇到相同的问题。
这使我得出一个结论,您应谨慎使用枚举。 甚至根本不应该使用枚举。
这是在enum列声明中添加可用选项会有多困难的示例
说你有这个:
Schema::create('blogs', function (Blueprint $table) {
$table->enum('type', [BlogType::KEY_PAYMENTS]);
$table->index(['type', 'created_at']);
...
并且需要提供更多类型
public function up(): void
{
Schema::table('blogs', function (Blueprint $table) {
$table->dropIndex(['type', 'created_at']);
$table->enum('type_tmp', [
BlogType::KEY_PAYMENTS,
BlogType::KEY_CATS,
BlogType::KEY_DOGS,
])->after('type');
});
DB::statement('update `blogs` as te set te.`type_tmp` = te.`type` ');
Schema::table('blogs', function (Blueprint $table) {
$table->dropColumn('type');
});
Schema::table('blogs', function (Blueprint $table) {
$table->enum('type', [
BlogType::KEY_PAYMENTS,
BlogType::KEY_CATS,
BlogType::KEY_DOGS,
])->after('type_tmp');
});
DB::statement('update `blogs` as te set te.`type` = te.`type_tmp` ');
Schema::table('blogs', function (Blueprint $table) {
$table->dropColumn('type_tmp');
$table->index(['type', 'created_at']);
});
}