symfony 尝试运行down/rollback命令时出现找不到Doctrine迁移类错误

2vuwiymt  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(187)

当我运行bin/console doctrine:migrations:list时,我看到迁移如下所示:
Application\Migrations\Version20210909072642
我正在尝试回滚迁移,并尝试了几个不同的版本:

bin/console --env=dev doctrine:migrations:execute 'Application\DoctrineMigrations\Version20210909072642' --down --no-interaction -vvv
bin/console --env=dev doctrine:migrations:execute Version20210909072642 --down --no-interaction -vvv
bin/console --env=dev doctrine:migrations:execute 20210909072642 --down --no-interaction -vvv

最近的DoctrineMigrationsBundle更新是否更改了此功能?
每次运行它时,都会出现以下错误:

In MigrationClassNotFound.php line 15:
                                                          
  [Doctrine\Migrations\Exception\MigrationClassNotFound]  
  Migration class "20210909072642" was not found?

我的Doctrine配置如下所示:

doctrine_migrations:
    migrations_paths:
        'Application\Migrations': 'app/DoctrineMigrations'
    storage:
        table_storage:
            table_name: 'migration_versions'
p5cysglq

p5cysglq1#

配置中的migrations_paths将迁移所在的名称空间设置为Application\Migrations,而不是Application\DoctrineMigrations
使用Application\Migrations\Version20210909072642运行migrate命令。

bin/console --env=dev doctrine:migrations:execute \
'Application\Migrations\Version20210909072642' --down --no-interaction -vvv
2skhul33

2skhul332#

很抱歉挖掘这个职位,但我有一个类似的关注Symfony 6。
我进行了一次测试迁移,遇到了同样的问题。
这里是我的迁移列表

+------------------------------------------+----------+---------------------+----------------+-------------+
| Migration Versions                                                                         |             |
+------------------------------------------+----------+---------------------+----------------+-------------+
| Migration                                | Status   | Migrated At         | Execution Time | Description |
+------------------------------------------+----------+---------------------+----------------+-------------+
| DoctrineMigrations\Version20220922124029 | migrated | 2022-09-22 14:41:13 | 3.352s         |             |
+------------------------------------------+----------+---------------------+----------------+-------------+

当我使用命令php bin/console d:m:e --down --no-interaction DoctrineMigrations\Version20220922124029时,我收到错误消息:

In MigrationClassNotFound.php line 15:
Migration class "DoctrineMigrationsVersion20220922124029" was not found?

这里\被转义,所以我们必须使用\\来代替,例如:d:m:e --down --no-interaction DoctrineMigrations\\Version20220922124029
现在我得到了[notice] Executing DoctrineMigrations\Version20220922124029 down的工作。
希望对同样情况的人有帮助。

相关问题