【问题标题】:Doctrine table migrations_versions column length教义表 migrations_versions 列长度
【发布时间】:2020-08-11 13:25:54
【问题描述】:

在带有 Doctrine Migrations 2.2.0 的 Symfony 5 上,我想执行一个自定义的学说迁移文件。 我的实体是使用 InnoDB utf8mb4_unicode_ci (在教义.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,因此这不是我的数据库的限制。 如何自动创建具有适当列长度的 migrations_versions 表?

config/packages/doctrine.yaml

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: App

config/packages/doctrine_migrations.yaml

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'

【问题讨论】:

  • 请分享您的配置。根据github.com/doctrine/DoctrineMigrationsBundle/issues/247,您可以使用少于 1024 个字符的方式
  • 另外,请分享第二条错误消息的完整堆栈跟踪
  • 已按要求提供的信息编辑
  • 您使用哪个版本的迁移包?
  • 最新的2.2.0,我在我的问题中添加信息

标签: symfony doctrine-migrations


【解决方案1】:

我的同事通过简单地评论该行找到了解决方案 version_column_length: 1024

【讨论】:

    【解决方案2】:

    这是因为使用的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多