Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unknown database type json requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it." while running php artisan migrate command

When I run:

php artisan migrate

and want to modify a string field to a text field like this:

//the old field that i want to modify in migration file
$table->string('description')->nullable();

//and the new text field
$table->text('description')->change();

I get the following error:

Unknown database type json requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

like image 320
Huy Nguyễn Avatar asked Jan 15 '18 03:01

Huy Nguyễn


3 Answers

try this solution may be this will work for you,

public function __construct()
{
    DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'text');
}

For further reading about this issue check Issue #15772 at laravel repo

like image 147
Mr. Pyramid Avatar answered Nov 15 '22 02:11

Mr. Pyramid


If you found this question at google, but your case is Symfony, but not Laravel - this is an answer.

Had same issue: Unknown database type json requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it. at Symfony/Sylius.

The reason - I had serverVersion=5.5 rather than serverVersion=5.7 at my app's .env file, when doctrine 2.6+ was installed by composer.

So right DATABASE_URL will be: DATABASE_URL=mysql://[email protected]/database_%kernel.environment%?serverVersion=5.7

like image 8
igormukhingmailcom Avatar answered Nov 15 '22 00:11

igormukhingmailcom


If using Symfony, you have to 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
like image 4
Tom Jowitt Avatar answered Nov 15 '22 02:11

Tom Jowitt