How to change enum type column in laravel migration?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Changing Enum Type Columns in Laravel Migrations Body:

Changing the data structure of your database is an essential part of web application development, and knowing how to modify enum type columns in Laravel migrations is crucial for a smooth workflow. In this blog post, we'll discuss the steps required to change the enum values in a table named packages from 'Kg.', 'Gm.' to 'Grams', 'Kgs.', 'Pounds'.

Before making any changes, ensure you have a backup of your database. You can create one by running the following command:

$ php artisan migrate:rollback --step=1
$ php artisan migrate:refresh --seed
$ php artisan db:seed --force

Now, let's create a new migration for the enum change. We can start by generating a new migration file using:

$ php artisan make:migration change_enum_weight_unit_table --create=packages

Open the newly created "migrate/2019_07_15_183452_change_enum_weight_unit_table.php" file and replace its content with:

enum('weight_unit', array('Grams', 'Kgs.', 'Pounds'))->nullable()->change();
        });
    }

    public function down() {
        Schema::table('packages', function (Blueprint $table) {
            $table->enum('weight_unit', array('Kg.', 'Gm.'))->nullable();
        });
    }
}

The migration file consists of two methods: up() and down(). The up() method is responsible for handling the changes we want to perform, while the down() method reverts all those changes in case something goes wrong. We have included a nullable() call to make sure that the enum column can still hold NULL values.

To run the migration, execute:

$ php artisan migrate

If the migration runs successfully without any errors, you are now able to change enum type columns in your Laravel migrations. But what if you encounter an error like "Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it"?

This issue occurs due to the differences between MySQL and other databases' handling of enum data types. In some cases, you may need to use a different approach:

public function up() {
    Schema::table('packages', function (Blueprint $table) {
        $table->string('weight_unit')->nullable();
    });

    DB::connection()->getSchemaBuilder()->disableForeignKeyConstraints();
    DB::statement("ALTER TABLE packages MODIFY COLUMN weight_unit ENUM ('Kgs.', 'Grams', 'Pounds') NULL DEFAULT NULL;");
    DB::connection()->getSchemaBuilder()->enableForeignKeyConstraints();
}

In this example, we first change the enum column to a string data type and migrate it. Then, using raw SQL queries, we modify the original enum structure within the database.

To summarize, changing enum type columns in Laravel migrations involves generating a new migration file, updating its content based on your desired changes, running the migration, and handling any potential errors that might occur. By closely following these steps, you can ensure smooth data transitions while maintaining your application's integrity.

Note: It is always recommended to make a backup of your database before making any significant changes to prevent catastrophic data loss in case of failures or unexpected scenarios.