php7 枚举,php-放在哪里/如何在Laravel中处理枚举?

"这篇博客讨论了在Laravel 5.1及更高版本中使用Enum列时遇到的问题,包括无法重命名或修改这些列。由于DoctrineDBAL的问题,即使更新到Laravel 5.8,问题依然存在。作者提供了示例代码,展示在尝试添加Enum列选项时的复杂性和潜在风险,并建议尽量避免使用Enum列以减少不必要的麻烦。"
摘要由CSDN通过智能技术生成

您根本不应该使用枚举。

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']);

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值