The version "latest" couldn't be reached, there are no registered migrations

Viewed 6374

So I'm setting up a Symfony 5 project and running the following commands to generate the database from entity annotations like this:

php bin/console doctrine:schema:validate
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

But it's not working as expected, and instead I'm just getting this error:

**[ERROR]** The version "latest" couldn't be reached, there are no registered migrations.

The diff command correctly generates the migration file containing the up() and down() functions however when I subsequently run the migrate command to generate the database it fails with the above error.

I also notice the file /config/packages/doctrine_migrations.yml has changed recently to this:

doctrine_migrations:
    migrations_paths:
        'App\Migrations': '%kernel.project_dir%/src/Migrations'

However it appears doctrine is looking outside this path for the migrations in the following path:

'%kernel.project_dir%/migrations'

How do you resolve the above error so that the migrate command works as expected and generates the database tables from the generated migration file?

php bin/console debug:config doctrine_migrations

Current configuration for extension with alias "doctrine_migrations"
=================================================================    ===

doctrine_migrations:
    migrations_paths:
        App\Migrations: /var/www/src/Migrations
    services: {  }
    factories: {  }
    storage:
        table_storage:
            table_name: null
            version_column_name: null
            version_column_length: null
            executed_at_column_name: null
            execution_time_column_name: null
    migrations: {  }
    connection: null
    em: null
    all_or_nothing: false
    check_database_platform: true
    custom_template: null
    organize_migrations: false
2 Answers

Check the namespace of your migration scripts and the config of the migration bundle. After moving the directory from src/migrations to migrations you have to change the namespace of the files to DoctrineMigrations and change the storage table name to the one, which exists (otherwise the new default migration table name is doctrine_migration_versions).

Here is my proposal: some migration file in /migrations

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

// ...

Config:

doctrine_migrations:
    migrations_paths:
        # namespace is arbitrary but should be different from App\Migrations
        # as migrations classes should NOT be autoloaded
        'DoctrineMigrations': '%kernel.project_dir%/migrations'

    storage:
        # Default (SQL table) metadata storage configuration
        table_storage:
            table_name: 'migration_versions'

this helps me to setup the project from scratch with Symfony5 and be backwards compatible with the current running production system.

I think you need to run the command "php bin/console make:migration" before "php bin/console make:migration:migrate"

I hope this is helpful.

Related