Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Platforms/MySQL80Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\Deprecations\Deprecation;

/**
Expand Down Expand Up @@ -31,4 +34,17 @@ public function createSelectSQLBuilder(): SelectSQLBuilder
{
return AbstractPlatform::createSelectSQLBuilder();
}

public function getDefaultValueDeclarationSQL(array $column): string
{
if (isset($column['default']) && ($column['type'] instanceof TextType || $column['type'] instanceof BlobType || $column['type'] instanceof JsonType)) {
// mysql requires text type column defaults to be written as expressions
// https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
// https://dev.mysql.com/doc/refman/8.4/en/data-type-defaults.html
// "The BLOB, TEXT, GEOMETRY, and JSON data types can be assigned a default value only if the value is written as an expression, even if the expression value is a literal"
return ' DEFAULT (' . $this->quoteStringLiteral($column['default']) . ')';
}

return parent::getDefaultValueDeclarationSQL($column);
}
}