DoctrineMigrationsBundle icon indicating copy to clipboard operation
DoctrineMigrationsBundle copied to clipboard

Migration diff command throws error "The schema provider is not available" on v3.1.1

Open allD245 opened this issue 4 years ago • 14 comments

After upgrading from v3.1.0 to 3.1.1, the command doctrine:migrations:diff throws the error "The schema provider is not available"

Here is the stack trace: Screen Shot 2021-04-22 at 2 49 16 pm

allD245 avatar Apr 22 '21 14:04 allD245

Same problem here, downgraded to 3.1.0 and everything works again

Thiplow avatar Apr 26 '21 15:04 Thiplow

Do you have multiple entity managers or did you define the connection or entity manager in your configuration files?

goetas avatar Apr 26 '21 19:04 goetas

I have done the same action (downgraded to 3.1.0) done by @Thiplow (Thanks :) ) to fix the problem.

@goetas I have multiple connections in my application. https://github.com/doctrine/DoctrineMigrationsBundle/compare/3.1.0...3.1.1, I think that the problem is in DependencyInjection/CompilerPass/ConfigureDependencyFactoryPass.php

Thank you for your help.

omarboussarsar avatar Apr 27 '21 10:04 omarboussarsar

Do you have multiple entity managers or did you define the connection or entity manager in your configuration files?

@goetas I've got a single connection in my application and it's defined in the config files

allD245 avatar Apr 27 '21 10:04 allD245

@omarboussarsar @allD245 can you share the doctrine migrations configs that you are using?

goetas avatar Apr 27 '21 11:04 goetas

@goetas

doctrine_migrations:
    storage:
        table_storage:
            table_name: migration_versions
    migrations_paths:
        'DoctrineMigrations': 'src/Migrations'
    connection:          default

here's my doctrine config as well

doctrine:
    dbal:
        # configure these for your database server
        # use postgresql for PostgreSQL
        # use sqlite for SQLite
        driver: 'mysql'
        server_version: '5.7'

        # only needed for MySQL
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
            JMoseCommandSchedulerBundle: ~
            ApplicationSonataMediaBundle: ~
            SonataMediaBundle: ~

allD245 avatar Apr 27 '21 12:04 allD245

@allD245 doctrine:migrations:diff needs the entity manager to be able to generate the ORM schema diff.

I think that your config file should be:

doctrine_migrations:
    storage:
        table_storage:
            table_name: migration_versions
    migrations_paths:
        'DoctrineMigrations': 'src/Migrations'
    em: default

goetas avatar Apr 27 '21 12:04 goetas

@goetas replacing connection with em and setting the value to default in my doctrine_migrations config fixes the doctrine:migrations:diff command for me on v3.1.1. Thanks!

allD245 avatar Apr 27 '21 12:04 allD245

@allD245 the diff command indeed requires using an entity manager, unless you provide a custom schema provider. The builtin schema provider relies on the entity manager providing a schema.

stof avatar Apr 27 '21 12:04 stof

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
                driver: 'pdo_pgsql'
                server_version: '12.6'
                charset: UTF8
            admin:
                url: '%env(resolve:DATABASE_ADMIN_URL)%'
                driver: 'pdo_pgsql'
                server_version: '12.6'
                charset: UTF8
    orm:
        auto_generate_proxy_classes: '%doctrine_method%'
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
doctrine_migrations:
    connection: admin
    migrations_paths:
        'Application\Migrations': '%kernel.project_dir%/migrations'
    storage:
        table_storage:
            table_name: 'migration_versions'

@goetas Thanks for your feedback. The solution proposed for @allD245 is not good for my example because I don't need to have many entity managers.

omarboussarsar avatar Apr 27 '21 12:04 omarboussarsar

Hi everyone.

I was having this error in a project. It has defined 2 connections, 1 for migrations. After reading this issue I have solved the error by defining an entitymanager that uses the connection defined for migrations, and using that EM in the doctrine_migrations.yaml:

doctrine_migrations:
# This was enough until version 3.1.1
#    connection: migrations
# Now this is what the project needs
    em: migrations_em
    ...
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                ...
            migrations:
                ...
    orm:
        default_entity_manager: default
        auto_generate_proxy_classes: false
        entity_managers:
            default:
                ...
            migrations_em:
                # If not specified, it uses 'default_connection' value
                connection: migrations
                ...

jomocag avatar May 12 '21 09:05 jomocag

@omarboussarsar your migrations config file should be

doctrine_migrations:
    em: default

(or even just omit the em/connection parameter)

The admin connection should be used only for production i guess, so:

doctrine_migrations:
    connection: admin

should be in config/packages/prod/doctrine_migrations.yaml

If you are using different connections even locally, then when running the migrations you should specify the --em parameter when running the diff command.

goetas avatar May 22 '21 11:05 goetas

Hey @goetas Your tip worked fine for me. Thanks :)

omarboussarsar avatar Jul 28 '21 09:07 omarboussarsar