Changing enum column in Laravel migration

Share on facebook
Share on twitter
Share on linkedin

Changing enum type columns is currently not supported in Laravel, and if you try to run something like:

You are about to get following exception:

Doctrine\DBAL\DBALException : Unknown database type enum requested, Doctrine\DBAL\Platforms\MariaDb1027Platform may not support it.

at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php:436
432|
433| $dbType = strtolower($dbType);
434|
435| if (! isset($this->doctrineTypeMapping[$dbType])) {
436| throw new DBALException(‘Unknown database type ‘ . $dbType . ‘ requested, ‘ . static::class . ‘ may not support it.’);
437| }
438|
439| return $this->doctrineTypeMapping[$dbType];
440| }

Exception trace:

1 Doctrine\DBAL\Platforms\AbstractPlatform::getDoctrineTypeMapping(“enum”)
/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php:128

2 Doctrine\DBAL\Schema\MySqlSchemaManager::_getPortableTableColumnDefinition()
/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:810

Currently there is no legal solution for this problem except avoiding enums, but there is workaround:

Create migration with following

And that will do the trick with enum update you are looking for.

Additionally you can create handle down functions to revert field status as it used to be:

 

 

0 0 vote
Article Rating

Subscribe to our newsletter

Be first to read new helpful post

Share this post with your friends

Share on linkedin
Share on xing
Share on twitter
Share on facebook

And the winners are …

As already announced we are going to launch 42workflows in the near future – a free open source package that will help you automate your

symphony process

Symfony Process with Laravel

Are you using ‘exec’, ‘passthru’, ‘shell_exec’ and ‘system’ php functions in your Laravel project? Taking care of security risks by yourself, as well as expecting

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments