7

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'
crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • Are you certain about the namespace `Application\DoctrineMigrations\Version20210909072642`? – Oluwafemi Sule Sep 17 '21 at 06:29
  • @OluwafemiSule Yes, I was able to run the `:migrate` without any issues – crmpicco Sep 17 '21 at 06:32
  • 1
    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\DoctrineMigrations` – Oluwafemi Sule Sep 17 '21 at 06:38
  • 1
    Thank you @OluwafemiSule - that was the issue. A PEBKAC issue, I think :-) Feel free to submit as the answer and I shall accept. – crmpicco Sep 17 '21 at 06:40

4 Answers4

10

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.

3PSY0N
  • 103
  • 1
  • 6
  • 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 --down – Ali Jan 19 '23 at 04:07
8

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
Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
2

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).
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.