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

Created on 12 Jan 2020  路  3Comments  路  Source: doctrine/dbal

Bug Report

| Q | A
|------------ | ------
| BC Break | yes
| Version | 2.10.0
| Framework | Laravel 6.x

Summary

When i run php artisan migrate, i got this error.

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

  at C:\xampp-php73\htdocs\blog\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")
      C:\xampp-php73\htdocs\blog\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\MySqlSchemaManager.php:128

  2   Doctrine\DBAL\Schema\MySqlSchemaManager::_getPortableTableColumnDefinition()
      C:\xampp-php73\htdocs\blog\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php:810

  Please use the argument -v to see more details.

Current behavior

when you have enum type on field, this error appear.

How to reproduce

Create new migration php artisan make:migration and fill the migration with script bellow:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddColumnsToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumn('users', 'gender')) {
            Schema::table('users', function (Blueprint $table) {
                $table->enum('gender', ['male', 'female'])->change();
            });
        }
        elseif ( ! Schema::hasColumn('users', 'gender')) {
                Schema::table('users', function (Blueprint $table) {
                    $table->enum('gender', ['male', 'female']);
                });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

    }
}

Expected behavior

it should run normally

Invalid Platforms Schema Introspection Type Mapping Types

Most helpful comment

Faced such problem in symfony.
Solution: link

# config/packages/doctrine.yaml
doctrine:
    dbal:
        mapping_types:
            enum: string

All 3 comments

Expected/known: ENUMs cannot be reverse-engineered into a Type, since each is different from all others. If you want to read a schema that has ENUMs, you will need to teach the platform to read them as string. See https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/mysql-enums.html#solution-1-mapping-to-varchars

Expected/known: ENUMs cannot be reverse-engineered into a Type, since each is different from all others. If you want to read a schema that has ENUMs, you will need to teach the platform to read them as string. See https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/mysql-enums.html#solution-1-mapping-to-varchars

Hello, i am also having some trouble with doctrine & enum type.
I used the second solution of the cookbook, it applied successfully but now if I want to make another migration, I am also getting the error "Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it."
But my EnumType should handle it, isn't it ?

My app's dependencies ares up-to-date.

My DBMS is maria DB 10.1.44 and unser doctrine.dbal config, I added

server_version: "mariadb-10.1.44"
types:
    enum_gender: App\DBAL\EnumGenderType

The generated SQL is

ALTER TABLE user ADD gender ENUM('female', 'male') DEFAULT NULL COMMENT '(DC2Type:enum_gender)'

This is working if I delete this field before each make:migration.

Faced such problem in symfony.
Solution: link

# config/packages/doctrine.yaml
doctrine:
    dbal:
        mapping_types:
            enum: string
Was this page helpful?
0 / 5 - 0 ratings