Framework: Migrations Rollback/Reset getting failed for migrations from subfolder or custom path

Created on 8 Sep 2016  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.6
  • PHP Version:7.0.9
  • Database Driver & Version: Mysql 5.6

    Description:

Migrations Rollback/Reset getting failed for migrations from subfolder or custom path.

Steps To Reproduce:

  1. Create a sub directory under database/migrations lets say xyz and it will looks like database/migrations/xyz/
  2. Create a migration into this new sub directory: php artisan make:migration create_user --path database/migrations/xyz/
  3. Run migration with path parameter as php artisan migrate --path database/migrations/xyz
  4. It will run successfully
  5. Next is to rollback or reset with php artisan migrate:reset -v it will through error as follows

[ErrorException]
Undefined index: 2016_09_05_192848_create_user

Exception trace:
() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:252
IlluminateFoundationBootstrapHandleExceptions->handleError() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:252
IlluminateDatabaseMigrationsMigrator->reset() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/ResetCommand.php:68
IlluminateDatabaseConsoleMigrationsResetCommand->fire() at n/a:n/a
call_user_func_array() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
IlluminateContainerContainer->call() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
IlluminateConsoleCommand->execute() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/symfony/console/Command/Command.php:256
SymfonyComponentConsoleCommandCommand->run() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
IlluminateConsoleCommand->run() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/symfony/console/Application.php:818
SymfonyComponentConsoleApplication->doRunCommand() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/symfony/console/Application.php:186
SymfonyComponentConsoleApplication->doRun() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/symfony/console/Application.php:117
SymfonyComponentConsoleApplication->run() at /var/www/smarttrainerlms/app.smarttrainerlms.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
IlluminateFoundationConsoleKernel->handle() at /var/www/smarttrainerlms/app.smarttrainerlms.com/artisan:35

My Findings:

I see first parameter is path in Illiminate/Database/Migrations/Migrator.php reset function but it is not passed from console Illiminate/Database/Console/Migrations/RollbackCommand.php and not even accepted from user.

Most helpful comment

Use something like this in a service provider:

$this->loadMigrationsFrom(base_path('database/migrations/xyz'));

Since you're using paths you must define them in a service provider in order for the migrator to load the files in them.

All 3 comments

You need to add custom path to custom migrations folder through a service provider.

Use something like this in a service provider:

$this->loadMigrationsFrom(base_path('database/migrations/xyz'));

Since you're using paths you must define them in a service provider in order for the migrator to load the files in them.

using folders for migration table organization and testing. sorry if duplicate. spent an hour trying to figure this out / very simple solution.

had undefined index problem on migrate:reset. composer dump-autload, deleting migrations table, restarting vagrant, lots of other attempts all failed.

simple solution: php artisan migrate:rollback --path=/database/migrations/folder

pass the path parameter to the rollback method. that's the solution if composer dump-autoload doesn't work for you on rollback or reset due to undefined index error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixsanz picture felixsanz  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

progmars picture progmars  路  3Comments

jackmu95 picture jackmu95  路  3Comments