Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
Tutorial Free

Laravel Enum in DB: How to Add New or Modify Old Values

August 15, 2023
1 min read

Enums are a popular field type in Databases to store a pre-defined list of keys. Do you know how to update enum values with Laravel? It's pretty simple!

Defining Enum Field Type in Laravel

You might have a field like this in your migration:

Schema::create('posts', function (Blueprint $table) {
// ...
$table->enum('status', ['Draft', 'Published', 'Archived']);
});

This gives you an option to have an exact list of values on the Database and not something else:


Changing Enum Values - Laravel 9 or Higher

In case you need to change the values, we can simply create a new migration and use the change() method:

Schema::table('posts', function (Blueprint $table) {
$table->enum('status', ['Draft', 'Published', 'Archived', 'Scheduled'])->change();
});

With this migration, you should now have an additional option in your Database:


What About Laravel 8 or Lower?

If you are using Laravel 8 or lower, you will have to install a 3rd party package:

composer require doctrine/dbal

Then, you can use change() method as well:

Schema::table('posts', function (Blueprint $table) {
$table->enum('status', ['Draft', 'Published', 'Archived', 'Scheduled'])->change();
});

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

I
iDev ✓ Link copied!

Maybe it's me, but this code doesn't really work, since ENUM has several limitations.

Currently on Laravel 10, with DBAL ^3.7 and getting same error as here: https://github.com/laravel/framework/issues/35096

DB::statement() may be a solution as in this example: https://github.com/laravel/framework/issues/35096#issuecomment-1512754452

AJ
Alexandre Junior da Costa ✓ Link copied!

Can confirm, this article's approach does not work on Laravel 10

N
Nerijus ✓ Link copied!

What errors do you get? Just tried and got no errors and enum value was added.

I
iDev ✓ Link copied!

My bad, wasn't descritive enough. The error itself, is when you try to update the enum field, previously created. For example, let's say you have an enum field, that accepts: ['approved', 'failed']

and you wish to add 'pending' as a possible entry to same column.

->change() will not work by default, on specified versions.

Have you tried changing the enum column?

N
Nerijus ✓ Link copied!

Yes. I created enum field. Then created another migrations where additional enum value is added how it is shown in this tutorial and it was added without any errors. You say doesn't work but don't say what it is? What error you get?

I
iDev ✓ Link copied!

The error is specified in github discussion. As stated on my comment:

getting same error as here: https://github.com/laravel/framework/issues/35096

N
Nerijus ✓ Link copied!

Maybe the issue is because you have DBAL package? It isn't needed for some time. Can't reproduce your error.

FM
Fatih Mehmet Kiriş ✓ Link copied!

Works on Laravel 11

Z
zircuitz ✓ Link copied!

Can confirm this works in Laravel 10!

I had a little trouble at first, but removing doctrine/dbal package from the project resolved the issue.

CD
Chris De David ✓ Link copied!

"modify" is only mentioned in the title. I'd like to know what happens if the client wants to modify one of the words? Eg. previously was "Man" and they want to change it to "Male"

CD
Chris De David ✓ Link copied!

I think this JUNIE answer would work...

public function up(): void
    {
        // 1) Allow both old and new enum values
        DB::statement("ALTER TABLE users MODIFY COLUMN gender ENUM('Man','Woman','Male','Female') NOT NULL");

        // 2) Update existing data
        DB::table('users')->where('gender', 'Man')->update(['gender' => 'Male']);
        DB::table('users')->where('gender', 'Woman')->update(['gender' => 'Female']);

        // 3) Restrict to new values only (re-apply NOT NULL/DEFAULT if needed)
        DB::statement("ALTER TABLE users MODIFY COLUMN gender ENUM('Male','Female') NOT NULL");
        // If you had a default, e.g. DEFAULT 'Male', use:
        // DB::statement("ALTER TABLE users MODIFY COLUMN gender ENUM('Male','Female') NOT NULL DEFAULT 'Male'");
    }