They can be an issue, and offer no real benefit IMO
Databases and enum
Hello,
Hmmm ... I wonder if setting an enum field in a field declaration (for example with MariaDB) is a good idea.
If the application evolves with future new items in the enum, I need to change the database definition. Whereas if I just change the enum items in the code, there are fewer changes to do.
What about your opinion about having enum in the database tables ?
Thanks for sharing your experience.
V
@vincent15000 I never use enum-type columns in migrations, because you can’t edit cases once you create the column; you have to completely drop it and re-create the column each and every time you want to change cases.
For this reason, I’ll just define the column as a string-type column, but then use an enumeration in my application code to enforce values:
$table->string('status');
enum OrderStatus: string
{
case Open = 'open';
case Processing = 'processing';
case Complete = 'complete';
case Cancelled = 'cancelled';
}
class Order extends Model
{
protected function casts(): array
{
return [
'status' => OrderStatus::class,
];
}
}
Please or to participate in this conversation.