Doctrine Migration class not found error when attempting to run down/rollback command
Asked Answered
F

4

9

When I run bin/console doctrine:migrations:list I see the Migration listed as:

Application\Migrations\Version20210909072642

I am attempting to rollback a migration and I have tried a few different versions:

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

Has this feature changed with a recent DoctrineMigrationsBundle update?

Every time I run it I get the following error:

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

My Doctrine config looks like this:

doctrine_migrations:
    migrations_paths:
        'Application\Migrations': 'app/DoctrineMigrations'
    storage:
        table_storage:
            table_name: 'migration_versions'
Fishhook answered 17/9, 2021 at 6:25 Comment(4)
Are you certain about the namespace Application\DoctrineMigrations\Version20210909072642?Closefisted
@OluwafemiSule Yes, I was able to run the :migrate without any issuesFishhook
You could try Application\Migrations\Version20210909072642 since the migrations_paths in your configuration sets the namespace your migration is located under as Application\Migrations and not Application\DoctrineMigrationsClosefisted
Thank you @OluwafemiSule - that was the issue. A PEBKAC issue, I think :-) Feel free to submit as the answer and I shall accept.Fishhook
C
10

migrations_paths in your configuration sets the namespace your migration is located under as Application\Migrations and not Application\DoctrineMigrations.

Run the migrate command with Application\Migrations\Version20210909072642.

bin/console --env=dev doctrine:migrations:execute \
'Application\Migrations\Version20210909072642' --down --no-interaction -vvv
Closefisted answered 17/9, 2021 at 6:43 Comment(0)
B
13

Sorry to dig up this post, but I had a similar concern with Symfony 6.

I did a test migration, and I had the same problem.

Here my migration list

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

When i use the command php bin/console d:m:e --down --no-interaction DoctrineMigrations\Version20220922124029 I got the error message:

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

Here the \ is escaped, so we have to use the \\ instead, like: d:m:e --down --no-interaction DoctrineMigrations\\Version20220922124029

and now i got [notice] Executing DoctrineMigrations\Version20220922124029 down working.

Hope it helps someone in same case.

Billionaire answered 22/9, 2022 at 13:12 Comment(1)
In Symfony 6.1.*, the use of the 2nd \ seems not needed anymore. At least in my case, "doctrine/doctrine-bundle": "^2.7", and "doctrine/doctrine-migrations-bundle": "^3.2",, I could simply use this command and it worked: php bin/console doctrine:migrations:execute DoctrineMigrations\Version20230118204719 --downNarceine
C
10

migrations_paths in your configuration sets the namespace your migration is located under as Application\Migrations and not Application\DoctrineMigrations.

Run the migrate command with Application\Migrations\Version20210909072642.

bin/console --env=dev doctrine:migrations:execute \
'Application\Migrations\Version20210909072642' --down --no-interaction -vvv
Closefisted answered 17/9, 2021 at 6:43 Comment(0)
D
4

I had the same problem:

Migration class "20221124124122" was not found?

And was solved when i ran:

  1. php bin/console d:m:list (To know how the interface see my migrations);
  2. php bin/console d:m:execute 'DoctrineMigrations\VersionYYYYMMDDSSxxx' --up (To migrate the version. Remember to put the version in quotes).
Dannettedanni answered 24/11, 2022 at 17:25 Comment(0)
M
0

I also got the error "Migration class "Version20230530204858" was not found?" when I launhed bin/console doctrine:migrations:execute --down DoctrineMigrations\Version20230530204858.

I added second slash just like here bin/console doctrine:migrations:execute --down DoctrineMigrations\\Version20230530204858 After that it worked.

Marquess answered 1/6, 2023 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.