尝试运行向下/回滚命令时出现 Doctrine 迁移类未找到错误

问题描述 投票:0回答:5

当我运行

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'
php symfony doctrine-orm doctrine doctrine-migrations
5个回答
13
投票

很抱歉挖出这篇文章,但我对 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
工作了。

希望它可以帮助遇到同样情况的人。


10
投票
您的配置中的

migrations_paths
将您的迁移所在的命名空间设置为
Application\Migrations
而不是
Application\DoctrineMigrations

使用

Application\Migrations\Version20210909072642
运行迁移命令。

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

4
投票

我也遇到了同样的问题:

Migration class "20221124124122" was not found?

当我运行时就解决了:

  1. php bin/console d:m:list
    (了解界面如何查看我的迁移);
  2. php bin/console d:m:execute 'DoctrineMigrations\VersionYYYYMMDDSSxxx' --up
    (迁移版本。记得将版本放在引号中)。

0
投票

当我启动

Migration class "Version20230530204858" was not found?
时,我也收到错误“
bin/console doctrine:migrations:execute --down DoctrineMigrations\Version20230530204858
”。

我添加了第二个斜杠,就像这里一样

bin/console doctrine:migrations:execute --down DoctrineMigrations\\Version20230530204858
之后就成功了。


0
投票

在 Symfony 6.x 中,您只需运行此命令即可回滚到以前的版本(如果需要,可以多次运行):

php bin/console doctrine:migrations:migrate prev
© www.soinside.com 2019 - 2024. All rights reserved.