你根本不应该使用枚举。
官方 Laravel 5.1 documentation 声明:
注意:目前不支持使用枚举列重命名表中的列。
当您的数据库表中有 enum 列时,就会发生这种情况。无论您是尝试rename another 列,还是将another 列更改为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']);
});
}