Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wonder95's avatar

Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable after updating to Laravel 11

After updating to Laravel 11 (woo hoo!!) when composer runs this

"post-autoload-dump": [
      "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
      "@php artisan package:discover --ansi"
    ],

I get this error

Generating autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Illuminate\Contracts\Container\BindingResolutionException 

  Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable while building [App\Console\Commands\FreshCommand, Illuminate\Database\Migrations\Migrator].

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:1118
    1114▕         } else {
    1115▕             $message = "Target [$concrete] is not instantiable.";
    1116▕         }
    1117▕ 
  ➜ 1118▕         throw new BindingResolutionException($message);
    1119▕     }
    1120▕ 
    1121▕     /**
    1122▕      * Throw an exception for an unresolvable primitive.

      +25 vendor frames 

  26  artisan:33
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

my App\Console\Commands\FreshCommand.php, is pretty simple

<?php

namespace App\Console\Commands;

use Illuminate\Database\Console\Migrations\FreshCommand as BaseFreshCommand;

class FreshCommand extends BaseFreshCommand
{
    /**
     * Drop all the database tables. Override base command for Mongo compatibility.
     *
     * @param  string  $database
     * @return void
     */
    protected function dropAllTables(string $database): void
    {
        $this->laravel['db']->connection($database)
            ->getMongoDb()
            ->drop();
    }
}

I actually also get it running any php artisan command, so it's not just the autoload.

I've looked through the upgrade guide, and I don't see anything that seems directly applicable. What am I missing?

0 likes
3 replies
LaryAI's avatar
Level 58

The error you're encountering is due to the MigrationRepositoryInterface not being properly bound in the service container. This can happen if the migration service provider is not registered correctly or if there are changes in the way Laravel handles migrations in the new version.

Here are the steps to resolve this issue:

  1. Check Service Providers: Ensure that the MigrationServiceProvider is registered in your config/app.php file. This is usually done automatically, but it's good to verify.

    'providers' => [
        // Other service providers...
        Illuminate\Database\MigrationServiceProvider::class,
    ],
    
  2. Update FreshCommand: Since you are extending the FreshCommand, make sure you are importing the correct classes and namespaces. Also, ensure that the parent constructor is called properly.

    <?php
    
    namespace App\Console\Commands;
    
    use Illuminate\Database\Console\Migrations\FreshCommand as BaseFreshCommand;
    use Illuminate\Database\Migrations\Migrator;
    use Illuminate\Contracts\Container\Container;
    
    class FreshCommand extends BaseFreshCommand
    {
        /**
         * Create a new command instance.
         *
         * @param  \Illuminate\Database\Migrations\Migrator  $migrator
         * @param  \Illuminate\Contracts\Container\Container  $container
         * @return void
         */
        public function __construct(Migrator $migrator, Container $container)
        {
            parent::__construct($migrator, $container);
        }
    
        /**
         * Drop all the database tables. Override base command for Mongo compatibility.
         *
         * @param  string  $database
         * @return void
         */
        protected function dropAllTables(string $database): void
        {
            $this->laravel['db']->connection($database)
                ->getMongoDb()
                ->drop();
        }
    }
    
  3. Clear Cache: Sometimes, cached configurations can cause issues. Clear the cache using the following commands:

    php artisan config:clear
    php artisan cache:clear
    php artisan config:cache
    
  4. Composer Autoload: Regenerate the autoload files to ensure all classes are properly loaded.

    composer dump-autoload
    
  5. Check Dependencies: Ensure that all your dependencies are up to date and compatible with Laravel 11. You can do this by running:

    composer update
    

By following these steps, you should be able to resolve the BindingResolutionException related to the MigrationRepositoryInterface. If the issue persists, double-check the Laravel upgrade guide for any additional changes that might affect your setup.

wonder95's avatar
wonder95
OP
Best Answer
Level 5

To avoid being this guy, I got my answer here, and added this in ApppServiceProvider

        $this->app->singleton(FreshCommand::class, function ($app) {
            return new FreshCommand($app['migrator']);
        });
1 like

Please or to participate in this conversation.