I am developing a Laravel application. What I am trying to do now is that I am trying to add a new enum type to the existing enum column.
This is how enum column is created/ migrated in the first place.
$table->enum('type', [BlogType::IMAGE, BlogType::TEXT]);
Now I am trying to add a new enum type to that column creating a new migration like this.
Schema::table('blogs', function (Blueprint $table) {
$table->enum('type', [BlogType::IMAGE, BlogType::TEXT, BlogType::VIDEO])->change();
});
As you can see, I added a VIDEO blog type.
When I run the migration, I got the following error.
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
Then I came across this link, Laravel 5.1 Unknown database type enum requested.
I tried adding the following in the constructor of the migration class.
\Illuminate\Support\Facades\DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
Then I got the following error when I run the migration.
Unknown column type "enum" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.
Now I am not renaming the column, I am just adding the new supported enum value. What would be the best solution and how can I do that, pelase?
TINYINTinstead, I personally dont like theENUMcolumn because of the way you need to define your options. With tinyint you can just use 0 to 128 (or 0 to 255 when unsigned) and resolve the integer to a string within php.