skip to Main Content

Running into the above error while attempting to run doctrine:schema:update in Symfony.

The error is happening in AbstractPlatform (part of libDoctrinePlatformsAbstractPlatform)

I’m checking and JSON is definitely registered in libDoctrineDBALTypesType.php

abstract class Type
{
    const TARRAY = 'array';
    const SIMPLE_ARRAY = 'simple_array';
    const JSON_ARRAY = 'json_array';
    const JSON = 'json';
...
}

Version of MySQL is 5.7.26 so that should be ok (json is a type here)

I’m just trying to figure out a workaround.

I tried adding

doctrine:
    dbal:
        types:
            enum: json

to doctrine.yaml

but that has had no effect. Does anyone know a workaround? I have no idea where the json file is being called…


Edit: I’ve come across a similar situation here but the answer is for Laravel:
"Unknown database type json requested, DoctrineDBALPlatformsMySQL57Platform may not support it." while running php artisan migrate command

Does anyone have any idea how to implement this for Symfony?

4

Answers


  1. Chosen as BEST ANSWER

    For those interested, here's a hackish workaround I came across here https://github.com/doctrine/orm/issues/6540

    In AbstractPlatform, I just modified the error check to convert json files into strings. Not ideal, but it got past this error.

     public function getDoctrineTypeMapping($dbType)
    {
        if ($this->doctrineTypeMapping === null) {
            $this->initializeAllDoctrineTypeMappings();
        }
    
        $dbType = strtolower($dbType);
    
    //inserted hack here
    
        if($dbType == 'json') {
            $dbType = 'string';
        }
    //
    
        if (!isset($this->doctrineTypeMapping[$dbType])) {
            throw new DoctrineDBALDBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
        }
    
        return $this->doctrineTypeMapping[$dbType];
    }
    

  2. how about

     enum: DoctrineDBALTypesJsonType
    
    Login or Signup to reply.
  3. make sure your dbal config is pointing at the correct server version:

    # Doctrine Configuration
    doctrine:
      dbal:
        driver: pdo_mysql
        host: "%database_host%"
        port: "%database_port%"
        dbname: "%database_name%"
        user: "%database_user%"
        password: "%database_password%"
        charset: utf8mb4
        server_version: 5.7
        default_table_options:
          charset: utf8mb4
          collate: utf8mb4_unicode_ci
          engine: InnoDB
    
    Login or Signup to reply.
  4. For me the fix was a composer update from a minor version to an other so it was a bug in the Doctrine DBAL.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search