使用自定义映射类型时,Symfony原则迁移失败



我试图引入一种自定义映射类型,但以以下方式失败:

1064 You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 
'localizedstring NOT NULL COMMENT '(DC2Type:localizedstring)', 
PRIMARY KEY(id)) D' at line 1

这是我的类型类:

namespace AppOrmCustomMappingTypes;
[...]
use DoctrineDBALPlatformsAbstractPlatform;
use DoctrineDBALTypesType;
[...]
class LocalizedStringType extends Type
{
const LOCALIZED_STRING = 'localizedstring';
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
[...]
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
[...]
}
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'localizedstring';
}
public function getName(): string
{
return self::LOCALIZED_STRING;
}
}

这是我的医生

doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
types:
localizedstring: AppOrmCustomMappingTypesLocalizedStringType
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App

我正在使用:

  • Symfony 5.1
  • 条令2.7.3

欢迎任何提示。如果需要更多信息,我很乐意提供。

错误是由于我误解了它的实际工作方式,并且没有阅读足够通用的教程:

解决方案->更改方法getSQLDeclaration(…(:

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'VARCHAR(256) COMMENT "localizedstring"';
}

有了这个要求,SQLCommentHint(…(也可以被删除。

最新更新