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

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

Closed
hrace009 opened this issue Jan 12, 2020 · 4 comments

Comments

@hrace009
Copy link

hrace009 commented Jan 12, 2020

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

@Ocramius
Copy link
Member

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

@Cartman34
Copy link

Cartman34 commented May 4, 2020

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.

@uginroot
Copy link

uginroot commented Sep 3, 2020

Faced such problem in symfony.
Solution: link

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

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants