Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown enum database type in migration file / Doctrine issue #1346

Closed
warrenca opened this issue May 18, 2013 · 10 comments
Closed

Unknown enum database type in migration file / Doctrine issue #1346

warrenca opened this issue May 18, 2013 · 10 comments

Comments

@warrenca
Copy link

I used an enum database type and when i run php artisan migration, i got this error

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

There's a solution to register the enum like this $platform->registerDoctrineTypeMapping('enum', 'string'); here http://wildlyinaccurate.com/doctrine-2-resolving-unknown-database-type-enum-requested but I wonder where to put that in Illuminate.

I tried to put that in Doctrine/DBAL/Schema/MySqlSchemaManager.php and it worked. Is there a better solution?

Line 113 $this->_platform->registerDoctrineTypeMapping('enum', 'string');
Line 114 $type = $this->_platform->getDoctrineTypeMapping($dbType);
@duellsy
Copy link
Contributor

duellsy commented Oct 11, 2013

Was there ever an elegant solution to this found rather than modifying MySqlSchemaManager.php file?

@ejunker
Copy link
Contributor

ejunker commented Oct 21, 2013

I ran into a similar issue with a legacy database that uses enum. I think I found a way to register the enum type and I put this in start/global.php but it is not working.

$platform = DB::getDoctrineSchemaManager()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

$platform = DB::getDoctrineConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

Anybody gotten this to work?

@endel
Copy link

endel commented Jul 2, 2015

Maybe this could help you out: #1186 (comment)

@duellsy
Copy link
Contributor

duellsy commented Jul 3, 2015

👍 Good work

@fero
Copy link

fero commented Feb 1, 2018

Set the engine to InnoDb:

$table->engine = 'InnoDB';

@Saif-hub24
Copy link

Saif-hub24 commented Apr 20, 2018

I am using laravel 5.2 but it still not working. Any help is much appreciated.

@farzamtm
Copy link

I ran into a similar issue with a legacy database that uses enum. I think I found a way to register the enum type and I put this in start/global.php but it is not working.

$platform = DB::getDoctrineSchemaManager()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

$platform = DB::getDoctrineConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

Anybody gotten this to work?

Yes. It worked for me.

@infostreams
Copy link

infostreams commented Aug 26, 2020

To do this in Laravel 7 you can create a file app\Providers\EnumServiceProvider.php with the following contents

<?php
namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class EnumServiceProvider extends ServiceProvider {
    public function boot() {
        // see https://github.com/laravel/framework/issues/1346
        $platform = DB::getDoctrineSchemaManager()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');

        $platform = DB::getDoctrineConnection()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');
    }
}

and then add App\Providers\EnumServiceProvider::class to the "providers" array in config/app.php to get it to run on boot.

@n3storm
Copy link

n3storm commented Aug 27, 2020

To do this in Laravel 7 you can create a file app\Providers\EnumServiceProvider.php with the following contents

<?php
namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class EnumServiceProvider extends ServiceProvider {
    public function boot() {
        // see https://github.com/laravel/framework/issues/1346
        $platform = DB::getDoctrineSchemaManager()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');

        $platform = DB::getDoctrineConnection()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');
    }
}

and then added App\Providers\EnumServiceProvider::class to the "providers" array in config/app.php to get it to run on boot.

This works on Laravel 6 too.

@fttx
Copy link

fttx commented Nov 16, 2022

To do this in Laravel 7 you can create a file app\Providers\EnumServiceProvider.php with the following contents

<?php
namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class EnumServiceProvider extends ServiceProvider {
    public function boot() {
        // see https://github.com/laravel/framework/issues/1346
        $platform = DB::getDoctrineSchemaManager()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');

        $platform = DB::getDoctrineConnection()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');
    }
}

and then add App\Providers\EnumServiceProvider::class to the "providers" array in config/app.php to get it to run on boot.

This solution fixes the enum issue with filament

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants