Reputation: 178
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.
Upvotes: 12
Views: 10968
Reputation: 495
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
Upvotes: 11
Reputation: 150
The right fix for this problem is to add a server version on config/database.php under the MySQL section.
'server_version' => "5.7"
because if you don't, Doctrine will use Doctrine\DBAL\Platforms\MySqlPlatform which supports all versions of MySQL since MySQL 5.0 which does not support JSON fields, and by adding the server_version Doctrine will load MySQL57Platform that have support for JSON instead of MySqlPlatform.
example of database MySQL config for Laravel 7:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'server_version' => "5.7",
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Upvotes: 3
Reputation: 7314
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
Upvotes: 5
Reputation: 3935
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
Upvotes: 17