Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EliasSoares's avatar

Bug? Changing a column of table that has an enum type.

Hi,

I'm trying to make a new migration for updating a table:

Originally, it has: id, name, gender

Gender is an ENUM, name STRING, and id INCREMENTS.

My migration is trying to change name to be nullable. Only this. But when I try to run the migration I receive:

[Doctrine\DBAL\DBALException]                                                                    
  Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

I'm not understanding why this is happing since I'm not changing the enum column at all.

0 likes
7 replies
mstnorris's avatar
Level 55

@EliasSoares Upon checking the Laravel 5.1 Migration Docs for Modifying Columns

Note: Renaming columns in a table with a enum column is not currently supported.

Renaming Columns

To rename a column, you may use the renameColumn method on the Schema builder. Before renaming a column, be sure to add the doctrine/dbal dependency to your composer.json file:

Schema::table('users', function ($table) {
    $table->renameColumn('from', 'to');
});

Note: Renaming columns in a table with a enum column is not currently supported.

This might fix your issue.

Another resource

Also a question on StackOverflow about this issue.

2 likes
EliasSoares's avatar

@mstnorris

The problem is: I'm not renaming the enum column, I'm not touching the enum column at all.

I'm only touching at name column.

My migration is only:

Schema::table('table_name', function ($table) {
    $table->string('name')->nullable()->change();
});
mstnorris's avatar

I know. Read the comment.

Note: Renaming columns in a table with a enum column is not currently supported.

This goes for all columns in a table where there is an enum type present. So you don't have to be modifying that field directly. As soon as one is present, you cannot modify that table.

1 like
timrpeterson's avatar

I just encountered this bug too. Very strange limitation, hopefully it will be fixed soon.

cbj4074's avatar

This bit me today, too.

The fix is simple. (Finding it, much less so.) Credit to http://stackoverflow.com/a/32860409/1772379 .

In the database migration file, add a constructor method, like so:

public function __construct()
{
    DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
}

Problem solved! At least in Laravel 5.1 (I haven't tried this in 5.2).

I should note that, in my specific case, I'm attempting to rename a different column on the table (not one that is of the ENUM() type), and I don't see any unwanted fallout from this approach. That's why this "bug" is so weird; it prevents one from modifying any column on a table that contains one or more ENUM() columns.

For anyone who is trying to modify an actual ENUM() column, this approach will likely change the column type to VARCHAR() or similar and the column will then accept any string.

15 likes
njt1982's avatar

@cbj4074 - thanks! What an amazingly simple fix for such a stupid error! How is this still a problem in Laravel/Lumen 5.4?!

1 like

Please or to participate in this conversation.