2
votes

I am using laravel 5.2 version and PHP 7.1. I am trying to migrate the files from my laravel project where I have code to check column existence as shown below -

if (!Schema::hasColumn('table1', 'column1')) {
    // Add column1
}

I know the code is perfectly fine and this has already worked several times while setting up the same code. But now I am trying this on separate machine and fails with an error -

[ErrorException]
Undefined property: stdClass::$column_name

I can get rid of this error if I remove the hasColumn checks from the code, but that's something I have written throughout the code and cannot modify each and every migration just for the sake of running migration.

Any help over this is much appreciated.

Stack trace:

[ErrorException]
Undefined property: stdClass::$column_name

Exception trace: () at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php:18 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php:18 Illuminate\Database\Query\Processors\MySqlProcessor->Illuminate\Database\Query\Processors{closure}() at n/a:n/a array_map() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php:21 Illuminate\Database\Query\Processors\MySqlProcessor->processColumnListing() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:40 Illuminate\Database\Schema\MySqlBuilder->getColumnListing() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:69 Illuminate\Database\Schema\Builder->hasColumn() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:217 Illuminate\Support\Facades\Facade::__callStatic() at /private/var/www/html/whitelabel_eb/database/migrations/2017_07_28_053158_add_columns_to_project_configurations_table.php:16 AddColumnsToProjectConfigurationsTable->{closure}() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:69 Illuminate\Database\Schema\Blueprint->__construct() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:207 Illuminate\Database\Schema\Builder->createBlueprint() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:116 Illuminate\Database\Schema\Builder->table() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:217 Illuminate\Support\Facades\Facade::__callStatic() at /private/var/www/html/whitelabel_eb/database/migrations/2017_07_28_053158_add_columns_to_project_configurations_table.php:103 AddColumnsToProjectConfigurationsTable->up() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:135 Illuminate\Database\Migrations\Migrator->runUp() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:112 Illuminate\Database\Migrations\Migrator->runMigrationList() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:85 Illuminate\Database\Migrations\Migrator->run() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:74 Illuminate\Database\Console\Migrations\MigrateCommand->fire() at n/a:n/a call_user_func_array() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Container/Container.php:507 Illuminate\Container\Container->call() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Console/Command.php:150 Illuminate\Console\Command->execute() at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Command/Command.php:238 Symfony\Component\Console\Command\Command->run() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Console/Command.php:136 Illuminate\Console\Command->run() at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:840 Symfony\Component\Console\Application->doRunCommand() at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:190 Symfony\Component\Console\Application->doRun() at /private/var/www/html/whitelabel_eb/vendor/symfony/console/Application.php:114 Symfony\Component\Console\Application->run() at /private/var/www/html/whitelabel_eb/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107 Illuminate\Foundation\Console\Kernel->handle() at /private/var/www/html/whitelabel_eb/artisan:35

2
Can you post the full stack trace instead of just the immediate error?John Ellmore
The same thing was experienced in post https://github.com/the-control-group/voyager/issues/1528. But they have used voyager as php artisan voyager:install --with-dummy.DIGVJSS
@JohnEllmore there is no stack trace, only the error shown above.DIGVJSS
Unfortunately, the error message above isn't very much to go off of. Are you running these migrations via the artisan command line tool? If so, I think adding -vvv should includes a full stack trace with any errors. So that'd be php artisan migrate -vvv.John Ellmore
Hi @JohnEllmore, I have added the stack trace in below answer.DIGVJSS

2 Answers

3
votes

I have did following changes to resolve this issue. Goto following path: /vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php

Change this, return $r->column_name; line number 18 to return $r->COLUMN_NAME;

0
votes

Looking at the problem, probably https://github.com/laravel/framework/pull/21037 this resolves it, but this change was made for Laravel 5.5. Laravel 5.2 isn't supported any more, so you could try to use your own fork with this fix when needed - you can use Composer VCS feature for that.

Of course upgrading to latest versions might be a good idea (a lot of issues were solved in later releases) but assuming your app is complex and doesn't have decent tests it might be risky.