Symfony 6执行make:migration报错,多种解决方案均无效
Symfony 6 执行
make:migration报错"The metadata storage is not up to date"的排查方案 问题重现
在Symfony 6环境执行symfony console make:migration时触发错误:
The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue
已尝试但无效的方案:
- 执行
bin/console doctrine:migrations:sync-metadata-storage(仍抛出相同异常) - 执行
bin/console doctrine:cache:clear-metadata - 配置
.env的DATABASE_URL为DATABASE_URL="mysql://root:@127.0.0.1:3306/ecommerce?serverVersion=10.4.24" - 执行
php bin/console cache:clear - 降级
doctrine/migrations至3.5.2
额外排查与解决步骤
1. 手动修复迁移元数据表
登录目标数据库,执行以下操作:
- 若
doctrine_migrations表不存在,手动创建:CREATE TABLE IF NOT EXISTS doctrine_migrations ( version VARCHAR(191) NOT NULL, executed_at DATETIME DEFAULT NULL, execution_time INT DEFAULT NULL, PRIMARY KEY(version) ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB; - 若表已存在,清空表内记录后重新执行
bin/console doctrine:migrations:sync-metadata-storage
2. 验证实体映射正确性
- 检查所有实体类的注解/XML/YAML映射,排查拼写错误、关联关系配置不当等问题
- 执行
bin/console doctrine:schema:validate命令,根据输出提示修复映射与数据库结构不匹配的问题
3. 确认数据库权限与连接
- 验证数据库用户(此处为root)拥有创建表、修改表、写入数据的完整权限
- 执行
bin/console doctrine:database:create --if-not-exists测试数据库连接可用性
4. 强制重置迁移文件
- 备份
migrations目录下的历史迁移文件后,删除所有迁移文件 - 执行
bin/console doctrine:migrations:generate生成基础迁移框架 - 再次执行
bin/console make:migration尝试生成新迁移
5. 检查Doctrine Migrations配置
打开config/packages/doctrine_migrations.yaml,确认配置无错误:
doctrine_migrations: migrations_paths: 'DoctrineMigrations': '%kernel.project_dir%/migrations' storage: table_storage: table_name: doctrine_migrations version_column_name: version version_column_length: 191 executed_at_column_name: executed_at execution_time_column_name: execution_time
内容的提问来源于stack exchange,提问作者Zaki Nacer
相关产品推荐
相关产品推荐

