Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.3 migrate:rollback issue #15081

Closed
gurminder opened this issue Aug 26, 2016 · 8 comments
Closed

Laravel 5.3 migrate:rollback issue #15081

gurminder opened this issue Aug 26, 2016 · 8 comments

Comments

@gurminder
Copy link

Running into a problem in Laravel 5.3

$migrations is an array instead of object, which throws non object error

Trying to get property of non-object

File Migrator.php needs to be updated Line 207 and 210 from

            foreach ($migrations as $migration) {
                $rolledBack[] = $files[$migration->migration];

                $this->runDown(
                    $files[$migration->migration],
                    (object) $migration, Arr::get($options, 'pretend', false)
                );
            }

to

            foreach ($migrations as $migration) {
                $rolledBack[] = $files[$migration["migration"]];

                $this->runDown(
                    $files[$migration["migration"]],
                    (object) $migration, Arr::get($options, 'pretend', false)
                );
            }
@tarikogut
Copy link

tarikogut commented Aug 26, 2016

composer dump-autoload did you try this command before migrate ??

@gurminder
Copy link
Author

gurminder commented Aug 26, 2016

yes, i did.

The issue is $files[$migration->migration]; needs to be replaced by $files[$migration["migration"]]; as $migrations is an array and it throws non object exception.

@tarikogut
Copy link

because working for me

@mcfdn
Copy link
Contributor

mcfdn commented Aug 26, 2016

Can you provide any extra information, such as a stack trace (php artisan migrate:rollback -v)? Working as intended on a fresh 5.3 install. I don't see why $migrations should be an object?

@gurminder
Copy link
Author

Yes, $migrations is an array, but the Laravel source code is using it as an object

I ran the command in the controller to print the stack trace

here's stack trace

in Migrator.php line 207
at HandleExceptions->handleError('8', 'Trying to get property of non-object', '---PATH---/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php', '207', array('paths' => array('---PATH---/database/migrations'), 'options' => array('pretend' => false, 'step' => '0'), 'rolledBack' => array(), 'steps' => '0', 'migrations' => array(array('migration' => '2016_08_26_193515_add_view_all_orders_for_company_permission', 'batch' => '34')), 'count' => '1', 'files' => array( ** REMOVED **   )) in Migrator.php line 207
at Migrator->rollback(array('---PATH---/database/migrations'), array('pretend' => false, 'step' => '0')) in RollbackCommand.php line 61
at RollbackCommand->fire()
at call_user_func_array(array(object(RollbackCommand), 'fire'), array()) in Container.php line 507
at Container->call(array(object(RollbackCommand), 'fire')) in Command.php line 169
at Command->execute(object(ArrayInput), object(BufferedOutput)) in Command.php line 256
at Command->run(object(ArrayInput), object(BufferedOutput)) in Command.php line 155
at Command->run(object(ArrayInput), object(BufferedOutput)) in Application.php line 818
at Application->doRunCommand(object(RollbackCommand), object(ArrayInput), object(BufferedOutput)) in Application.php line 186
at Application->doRun(object(ArrayInput), object(BufferedOutput)) in Application.php line 117
at Application->run(object(ArrayInput), object(BufferedOutput)) in Application.php line 64
at Application->call('migrate:rollback', object(Collection)) in Kernel.php line 213
at Kernel->call('migrate:rollback') in Facade.php line 238
at Facade::__callStatic('call', array('migrate:rollback')) in TestAPIController.php line 40
at TestAPIController->testMethod()
at call_user_func_array(array(object(TestAPIController), 'testMethod'), array()) in Controller.php line 52
at Controller->callAction('testMethod', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(TestAPIController), 'testMethod') in Route.php line 189
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HandleCors.php line 34
at HandleCors->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 263
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 38
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HandleCors.php line 34
at HandleCors->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 57

@gurminder
Copy link
Author

Exception trace:
() at ---PATH---/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:207
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at ---PATH---/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:207
 Illuminate\Database\Migrations\Migrator->rollback() at ---PATH---/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RollbackCommand.php:61
 Illuminate\Database\Console\Migrations\RollbackCommand->fire() at n/a:n/a
 call_user_func_array() at ---PATH---/vendor/laravel/framework/src/Illuminate/Container/Container.php:507
 Illuminate\Container\Container->call() at ---PATH---/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
 Illuminate\Console\Command->execute() at ---PATH---/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at ---PATH---/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
 Illuminate\Console\Command->run() at ---PATH---/vendor/symfony/console/Application.php:818
 Symfony\Component\Console\Application->doRunCommand() at ---PATH---/vendor/symfony/console/Application.php:186
 Symfony\Component\Console\Application->doRun() at ---PATH---/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at ---PATH---/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
 Illuminate\Foundation\Console\Kernel->handle() at ---PATH---/artisan:35

@mcfdn
Copy link
Contributor

mcfdn commented Aug 26, 2016

Have you set the PDO return mode to FETCH_ASSOC? E.g. DB::setFetchMode(PDO::FETCH_ASSOC);. Seems that as Migrator.php expects an object, it breaks when PDO returns an array.

@gurminder
Copy link
Author

Thank you, I have it as FETCH_ASSOC. It works after changing to FETCH_CLASS.

This should still be fixed or documented in upgrade guide by Laravel team. This will break up a lot of raw queries that are used in this project that need to be updated.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants