在Symfony 5和2.2.0中,我想执行一个定制的原则迁移文件。我的实体是用InnoDB utf8mb4_unicode_ci (doctrine.yaml中的默认值)创建的。
当我执行bin/console doctrine:migrations:status --show-versions时,我得到:
An exception occurred while executing 'CREATE TABLE migration_versions (version VARCHAR(1024) NOT NULL, executed_at DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)', PRIMARY KEY(version)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes因此,我修改了doctrine_migrations.yaml,并将version_column_length的值更改为255,但是现在使用相同的命令
In BaseNode.php line 425:
Invalid configuration for path "doctrine_migrations.storage.table_storage.version_column_length": The minimum length for the version column is 1024.
In ExprBuilder.php line 187:
The minimum length for the version column is 1024. 可以将自动创建的实体表的varchar长度更改为1024,因此这不是对我的db的限制。如何自动创建具有适当列长的migrations_versions表?
config/packages/配理.config
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
enum: string
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
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: 'App\Entity'
alias: Appconfig/packages/doctrine.config
doctrine_migrations:
migrations_paths:
'DoctrineMigrations': '%kernel.project_dir%/src/Migrations'
storage:
table_storage:
table_name: 'migration_versions'
version_column_name: 'version'
version_column_length: 1024
executed_at_column_name: 'executed_at'发布于 2020-10-27 14:34:24
我的同事通过简单地评论version_column_length: 1024行找到了解决方案
发布于 2020-11-22 10:37:23
这是因为所使用的MySQL版本中的键长度限制。对于较早版本的MySQL,它可能较小,而且还依赖于所使用的排序规则。您必须检查用于查找允许的最大键长度的MySQL版本,然后找到可以与正在使用的排序规则一起使用的列的最大大小。该长度可用于配置的原则迁移文件中的选项version_column_length (例如: migrations.php或migrations.xml等)。
关于键的最大长度的很好的解释可以在以下问题的答案中找到。
Specified key was too long; max key length is 767 bytes
在我的例子中,它是有限的191,因为我使用的是MySQL 5.6
发布于 2022-07-18 12:23:56
在我的例子中,我将version_column_length从1024更改为255。
https://stackoverflow.com/questions/63359133
复制相似问题